> I have a tuple like this: > > T = ("One","Two","Three","Four") > > Is there any built-in way to find what is the index of "Two" withouot > looping within the tuple? > > Is the same feature available for lists or dictionaries?
Lists have a index() method. For the tuple, you can convert it to a list: indexOfTwo = list(T).index("Two") Dictionaries don't have a defined ordering, so there's no similar functionality (because results would be meaningless) unless you convert it to a list, and then you can snag its index in the arbitrarily-ordered results (or sort the results first). If you just need to test for presence, and don't need the index, you can use "Two" in T Just a few ideas... -tkc -- http://mail.python.org/mailman/listinfo/python-list