Get loop count inside a Python FOR loop

后端 未结 5 988
故里飘歌
故里飘歌 2020-11-28 00:42

In a Python for loop that iterates over a list we can write:

for item in list:
    print item

and it neatly goes through all t

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-28 01:12

    I know rather old question but....came across looking other thing so I give my shot:

    [each*2 for each in [1,2,3,4,5] if each % 10 == 0])
    

提交回复
热议问题