count in 'for ... in ...'

Achim Domma achim.domma at
Tue Nov 6 16:50:17 CET 2001


if I have a list of strings and want to display with a count in front of it
I usualy do something like:

for i in range(len(my_list)):
    print i,". ",my_list[i]

but I think the

for s in my_list:
    print ...

Syntax is much cleaner, because it clearly says what I'm doing. So I asked
myself : is there a way to get the internal count in 'for' ? Of course
it would be the same as the first version, but in my opinion it would fit
perfectly in the 'python-way' to say what one is doing.


More information about the Python-list mailing list