list indexing

Batista, Facundo FBatista at uniFON.com.ar
Fri Aug 1 16:13:36 CEST 2003


#- Hello, I am rather new to python and I have come across a 
#- problem that
#- I can not find an answer to any where I my books. What I 
#- would like to
#- know is if there is a way to get the index number of a list 
#- element by
#- name. Sort of the inverse of the .index() method.
#- 
#- For example
#- 
#- list = ['this', 'is', 'a', 'list']
#- for item in list:
#-   if item = 'list':
#-     print ????
#- 
#- 
#- ???? Is where I want to be able to get the index number, in this case
#- 3 from the list in a simple fasion.



It's just index:

>>> list = ['this', 'is', 'a', 'list']
>>> for item in list:
	print list.index(item), item

	
0 this
1 is
2 a
3 list
>>> 

.	Facundo








More information about the Python-list mailing list