"Matthew Thorley" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I must say I am *very* suprised that python does not have a way to look > up what key is pointing to a given object
But it does. Of course, there could be zero to many keys in any dictionary pointing to any particular value object >--without scanning the whole list that is. That's one way. Another is a reverse dict (for hashable values turned into keys) with the value being a list of zero to many keys. A third (and fastest of these) is to keep the key with the value. >Is that what list.index() does under-the-hood? I mean is > list.index(y) just the same as > > itemnum = 0 > for item in list: > if y == item: > return itemnum > else: > itemnum = itemnum+1 More or less, yes. If your list is sorted, you can use binary search in the bisect module. Terry J. Reedy -- http://mail.python.org/mailman/listinfo/python-list