Better way to iterate over indices?

Billy Mays noway at nohow.com
Tue Jun 21 14:05:00 EDT 2011


I have always found that iterating over the indices of a list/tuple is 
not very clean:

for i in range(len(myList)):
     doStuff(i, myList[i])




I know I could use enumerate:

for i, v in enumerate(myList):
     doStuff(i, myList[i])

...but that stiff seems clunky.

Are there any better ways to iterate over the indices of a list /tuple?

--Bill



More information about the Python-list mailing list