Counting iterations

Will McGugan news at NOwillmcguganSPAM.com
Fri Apr 8 17:16:48 EDT 2005


Derek Basch wrote:
> Is there a better way to count iterations that this?:
> 
> pets = 0
> for i in pets:
>     pets += 1
>     print "pet" + "#" + pets
> 

You can use 'enumerate' to get the index, but the code above wont work - 
you are trying to iterate over a non-sequence.

Will McGugan

-- 
"".join( [ {'@':'@','.':'.'}.get(c,None) or chr(97+((ord(c)-97)+13)%26) 
for c in "jvyy at jvyyzpthtna.pbz" ] )



More information about the Python-list mailing list