Best way to have a for-loop index?

Klaas mike.klaas at gmail.com
Thu Apr 6 00:24:45 EDT 2006


roy spewed:
> The real question is *why* do you want the index?
>
> If you're trying to iterate through list indicies, you're probably trying
> to write C, C++, Fortran, Java, etc in Python.

Could we stop the stupid continual beratement of people validly asking
about enumerate()?  Yes, we want to discourage:

for i in xrange(len(seq)):
   seq[i]

but in this case, and many other cases, that is clearly not the
question being posed.

enumerate is one of the most useful built-ins and a love the way it
reads in code.  Stop the index-hate.

-Mike




More information about the Python-list mailing list