kame kame - 1 year ago 119
Python Question

Position in an list? (Python)

I will check if a word exists in a list.
How can I show the position of this word?

Answer Source
list = ["word1", "word2", "word3"]
   print list.index("word1")
except ValueError:
   print "word1 not in list."

This piece of code will print 0, because that's the index of the first occurrence of "word1"

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download