getting an item's list index

Riccardo Galli riccardo_togli_questo at _e_questo_sideralis.net
Sat Apr 19 09:28:18 EDT 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

Hi Michael.

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)):
	contents[i] ...

Ciao,
Riccardo

-- 
-=Riccardo Galli=-

 _,e.
s~  ``
 ~@.   ideralis Programs
.   ol 
 `**~  http://www.sideralis.net





More information about the Python-list mailing list