getting an index in a for loop

Erik Max Francis max at alcyone.com
Fri Jan 31 22:41:38 EST 2003


Chad Netzer wrote:

> Or the always-in-style, oldie-but-goodie method (from Python 1.x
> onwards):
> 
> s = 'abcdefg'
> for i in xrange( len( s ) ):
>     print i, s[i]

Note this solution also does not suffer from performance problem if the
sequence is truly large.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ It is much safer to obey than to rule.
\__/ Thomas a Kempis
    Sade Deluxe / http://www.sadedeluxe.com/
 The ultimate Sade encyclopedia.




More information about the Python-list mailing list