using the for loop counter in python Nov

Even with all the powerful tools Python loops do for you, sometimes you need to grab the good ol' loop counter.

There are a couple of different ways you can do this. The cleanest method that I found so far is to use the enumerate function. You can do something like this:

test = ['a', 'b', 'c']

for counter, value in enumerate(test):
    print counter, value
Bookmark and Share
blog comments powered by Disqus