object's list index
Fredrik Lundh
fredrik at pythonware.com
Fri Mar 3 07:38:41 EST 2006
William Meyer wrote:
> I need to get the index of an object in a list. I know that no two objects
> in the list are the same, but objects might evaluate as equal. for example
>
> list = [obj1, obj2, obj3, obj4, obj5]
> for object in list:
> objectIndex = list.index(object)
> print objectIndex
for objectIndex, object in enumerate(list):
print objectIndex, object
(note that both object and list are commonly used builtins, so you should probably
use other names in your code to avoid weird TypeErrors later on).
</F>
More information about the Python-list
mailing list