<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Dec 30, 2016 at 8:04 PM, Ethan Furman <span dir="ltr"><<a href="mailto:ethan@stoneleaf.us" target="_blank">ethan@stoneleaf.us</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div id="gmail-:5uc" class="gmail-a3s gmail-aXjCH gmail-m159526935c648a17">No.  It is possible to have two keys be equal but different -- an easy example is 1 and 1.0; they both hash the same, equal the same, but are not identical.  dict has to check equality when two different objects hash the same but have non-matching identities.</div></blockquote></div><br></div><div class="gmail_extra"><br></div><div class="gmail_extra"><div class="gmail_extra">Python 3.6.0 (default, Dec 24 2016, 00:01:50)</div><div class="gmail_extra">[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin</div><div class="gmail_extra">Type "help", "copyright", "credits" or "license" for more information.</div><div class="gmail_extra">>>> d = {1: 'int', 1.0: 'float'}</div><div class="gmail_extra">>>> d</div><div class="gmail_extra">{1: 'float'}</div><div class="gmail_extra"><br></div><div class="gmail_extra"><br></div><div class="gmail_extra">IPython 5.1.0 -- An enhanced Interactive Python.<br></div><div class="gmail_extra"><br></div><div class="gmail_extra"><div class="gmail_extra">In [1]: class Foo:</div><div class="gmail_extra">   ...:     def __eq__(self, other):</div><div class="gmail_extra">   ...:         return True</div><div class="gmail_extra">   ...:     def __init__(self, val):</div><div class="gmail_extra">   ...:         self.val = val</div><div class="gmail_extra">   ...:     def __repr__(self):</div><div class="gmail_extra">   ...:         return '<Foo %r>' % self.val</div><div class="gmail_extra">   ...:     def __hash__(self):</div><div class="gmail_extra">   ...:         return 42</div><div class="gmail_extra">   ...:</div><div class="gmail_extra"><br></div><div class="gmail_extra">In [2]: f1 = Foo(1)</div><div class="gmail_extra"><br></div><div class="gmail_extra">In [3]: f2 = Foo(2)</div><div class="gmail_extra"><br></div><div class="gmail_extra">In [4]: x = {f1: 1, f2: 2}</div><div class="gmail_extra"><br></div><div class="gmail_extra">In [5]: x</div><div class="gmail_extra">Out[5]: {<Foo 1>: 2}</div></div><div class="gmail_extra"><br></div><div class="gmail_extra"><br></div><div class="gmail_extra"><br></div><div class="gmail_extra">I'm having trouble showing that two equal but nonidentical objects can both be in the same dict.</div></div></div>