Newbie question on tuples

Carmine Noviello cnoviello at
Thu Feb 5 22:30:12 CET 2004

"Thomas Philips" <tkpmep at> wrote in message
news:b4a8ffb6.0402051309.4292ccf1 at

> How does one find the position of an item in a tuple. i.e. If the
> tuple is ("rock", "scissors", "paper"), what function (or method) do I
> call with "rock" to get 0 or with "paper" to get 2?
> Thomas Philips

def indexOf(t, elem):
	ret = -1 #Not in tuple
	for i in range(len(t)):
		if t[i] == elem:
			ret = i
	return ret


Posted via Mailgate.ORG Server - http://www.Mailgate.ORG

More information about the Python-list mailing list