Can I use index information inside the map function?

前端 未结 5 1885
猫巷女王i
猫巷女王i 2020-12-28 14:40

Let\'s assume there is a list a = [1, 3, 5, 6, 8].

I want to apply some transformation on that list and I want to avoid doing it sequentially, so someth

5条回答
  •  盖世英雄少女心
    2020-12-28 15:17

    # Python3
    map(lambda args: print(args[0],args[1]) ,enumerate(a_list))
    # use arg list, just get the result with index
    
    # Python2
    map(lambda index,content: print(index,content) ,enumerate(a_list))
    

提交回复
热议问题