getting an item's list index
riccardo_togli_questo at _e_questo_sideralis.net
Sat Apr 19 15:28:18 CEST 2003
On Sat, 19 Apr 2003 14:57:45 +0200, Michael Anckaert wrote:
> Hello all,
> I have a list called contents. If one of the elements has the value
> "item1" for example, how can I get that elements index?
> for item in contents:
> # here I need to get that items index
You're speaking about 'index' method.
contents.index(item) gives you what you want.
Maybe suits more your needs the range function
for i in range(len(contents)):
~@. ideralis Programs
More information about the Python-list