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

Achim Domma achim.domma at syynx.de
Tue Nov 6 10:50:17 EST 2001


Hi,

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 ...in' ? 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.

greetings
Achim





More information about the Python-list mailing list