[Tutor] Iterating over a string: index and value

Alan Gauld alan.gauld at freenet.co.uk
Fri Feb 10 23:51:43 CET 2006


> generate the index and value of a string's characters in a single for
> statement.  Is this true or did imagine it?

>>> for i,c in enumerate('fred'): print i,c
...
0 f
1 r
2 e
3 d


Like that?

Alan G.



More information about the Tutor mailing list