Answers for "for counter in python"

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
1

Counter in python

from collections import Counter
strl = "aabbaba"
print(Counter(str1))

Counter({'a': 4, 'b': 3})
Posted by: Guest on August-16-2021

Python Answers by Framework

Browse Popular Code Answers by Language