Steve Haley wrote: > Hello everyone, > > I need to do something very simple but I'm having trouble finding the > way to do it - at least easily. I have created a tuple and now need to > find the position of individual members of that tuple. Specifically, > the tuple is something like: words = ("you", "me", "us", "we", "and", > "so", "forth") and I need to be able to name a member, for example, "us" > and find what the position (index) of that word is in the tuple.
If you can use a list instead of a tuple you can use the index() method. >>> words = ["you", "me", "us", "we", "and", "so", "forth"] >>> words.index('me') 1 >>> words.index('so') 5 There is no index() method for a tuple. This is probably because in GvR's view, tuples are analogous to records - they are heterogeneous collections where position matters. Lists are for homogeneous collections. In this view, tuple.index() doesn't make sense. list.index() is documented here: http://docs.python.org/lib/typesseq-mutable.html You found the right chapter of the Lib Ref but the wrong section. Kent _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor