<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Dec 30, 2016 at 8:10 PM, <span dir="ltr"><<a href="mailto:jab@math.brown.edu" target="_blank">jab@math.brown.edu</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 dir="ltr"><span class="gmail-m_575565152715937358m_-9167739862345500627m_-2652507907728150281m_-1302029173622835551m_-625012948502035022m_-1305066991870199879gmail-"><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-m_575565152715937358m_-9167739862345500627m_-2652507907728150281m_-1302029173622835551m_-625012948502035022m_-1305066991870199879gmail-m_3177351254297167845gmail-:5uc" class="gmail-m_575565152715937358m_-9167739862345500627m_-2652507907728150281m_-1302029173622835551m_-625012948502035022m_-1305066991870199879gmail-m_3177351254297167845gmail-a3s gmail-m_575565152715937358m_-9167739862345500627m_-2652507907728150281m_-1302029173622835551m_-625012948502035022m_-1305066991870199879gmail-m_3177351254297167845gmail-aXjCH gmail-m_575565152715937358m_-9167739862345500627m_-2652507907728150281m_-1302029173622835551m_-625012948502035022m_-1305066991870199879gmail-m_3177351254297167845gmail-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>...</div><div class="gmail_extra">I'm having trouble showing that two equal but nonidentical objects can both be in the same dict.<br></div></span></div>
</blockquote></div><br></div><div class="gmail_extra">(Because they can't, though) your point stands that Python had to call __eq__ in these cases.</div><div class="gmail_extra"><br></div><div class="gmail_extra">But with instances of large, immutable, ordered collections, an application could either:</div><div class="gmail_extra"><br></div><div class="gmail_extra">1. accept that it might create a duplicate, equivalent instance of an existing instance with sufficient infrequency that it's okay taking the performance hit, or</div><div class="gmail_extra"><br></div><div class="gmail_extra">2. try to avoid creating duplicate instances in the first place, using the existing, equivalent instance it created as a singleton. Then a set or dict lookup could use the identity check, and avoid the expensive __eq__ call.</div><div class="gmail_extra"><br></div><div class="gmail_extra"><br></div><div class="gmail_extra">I think it's much more important to focus on what happens with unequal instances here, since there are usually many more of them. And with them, the performance hit of the __eq__ calls definitely does not necessarily dominate that of __hash__. Right?</div></div>