Unexpected comparisons in dict lookup

2014-03-18 Thread Steven D'Aprano
I stumbled across this unexpected behaviour with Python 2.7 and 3.3. When you look up a key in a dict, the key is sometimes compared against other keys twice instead of just once. First, a class that reports when it is being tested for equality, with a fixed hash so that we get collisions

Re: Unexpected comparisons in dict lookup

2014-03-18 Thread Ian Kelly
On Tue, Mar 18, 2014 at 8:20 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: I stumbled across this unexpected behaviour with Python 2.7 and 3.3. When you look up a key in a dict, the key is sometimes compared against other keys twice instead of just once. From what I can see