Chris Angelico <ros...@gmail.com> writes: >> Would I have to do an O(n) search to find my key? > Iterate over it - it's an iterable view in Py3 - and compare.
I think the question was whether the O(n) search could be avoided, not how to do it. I don't see a way to avoid it. There is fundamental brokenness in having unequal objects compare as equal, and the breakage messes up the dictionary when those objects are used as keys. Solution is to either fix the object equality test, or wrap them in something (maybe a tuple containing the objects and the distinguishing fields that are missing from the original object's equality method) that treats unequal objects as unequal. -- https://mail.python.org/mailman/listinfo/python-list