object's list index

Sybren Stuvel sybrenUSE at YOURthirdtower.com.imagination
Fri Mar 3 07:40:59 EST 2006


Iain King enlightened us with:
> i = 0
> for object in list:
>     objectIndex = i
>     print objectIndex
>     i += 1

Why not:

for index, object in enumerate(list):
    print index

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
                                             Frank Zappa



More information about the Python-list mailing list