Kent Johnson <kent <at> kentsjohnson.com> writes: > In either case enumerate() is your friend. To find an > item by identity: > > def index_by_id(lst, o): > for i, item in enumerate(lst): > if item is o: > return i > raise ValueError, "%s not in list" % o > > If you just want the index available inside the loop, this replaces your > original loop: > for i, object in enumerate(lst): > print i > > Kent
Thanks, both you and Fredrik Lundh suggested enumerate, which seems like the best solution. I just need the index inside the loop, but thanks again for both solutions. -- http://mail.python.org/mailman/listinfo/python-list