Answers for "python for loop with counter"

27

python3 iterate through indexes

items=['baseball','basketball','football']
for index, item in enumerate(items):
    print(index, item)
Posted by: Guest on May-07-2020
7

for loop with index python3

colors = ["red", "green", "blue", "purple"]

for i in range(len(colors)):
    print(colors[i])
Posted by: Guest on January-28-2020
1

python for loop counter

# The pythonic way to find the count in a for-in loop (by using 'enumerate')

#count=0
for idx, item in enumerate(list):
    print item
    #count +=1
    #if count % 10 == 0:
    if (idx+1) % 10 == 0:
        print 'did ten'
Posted by: Guest on August-08-2021
0

python for loop get iteration number

for idx, item in enumerate(list):
    print(item)
    print('Iteration number: ', idx)
Posted by: Guest on September-09-2020

Python Answers by Framework

Browse Popular Code Answers by Language