Tuple index

Larry Bates lbates at syscononline.com
Sun Feb 20 20:18:53 EST 2005


Tuples don't have all the nice methods that lists have
so convert it to a list.

tuple=('a','b','c','d')
l=list(tuple)

now you can do:

list.index('c')

which returns 2

Remember index returns -1 when nothing is found.

Larry Bates


Steve M wrote:
> Hello,
> 
>         I'm trying to figure out the index position of a tuple member. 
> I know the member name, but I need to know the members index position. I
> know that if I use the statement print tuple[4] that it will print the
> contents of that location. What I don't understand is if I know that foo is
> a member of tuple, how do I get foo's index position.
> Thanks-in-Advance
> Steve



More information about the Python-list mailing list