list indexing

Batista, Facundo FBatista at uniFON.com.ar
Fri Aug 1 13:52:37 EDT 2003


#- But this only works for single instances, since it finds the first:
#- >>> li = 'this is a list with a repeated word in this list'.split()
#- >>> for item in li: print li.index(item), item
#- ...
#- 0 this
#- 1 is
#- 2 a
#- 3 list
#- 4 with
#- 2 a
#- 6 repeated
#- 7 word
#- 8 in
#- 0 this
#- 3 list
#- 
#- I wondered at first if there was a way to do it directly, 
#- but I usually
#- ended up making a companion range of indexes to zip(), and 
#- now will use
#- enumerate(). Was there a direct method that I never found?

What is the specific behaviour are you searching for?

Ask for the index and receive a tuple with all the indeces?

.	Facundo





More information about the Python-list mailing list