<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Thu, Jan 5, 2017 at 9:10 PM Stephen J. Turnbull <<a href="mailto:turnbull.stephen.fw@u.tsukuba.ac.jp">turnbull.stephen.fw@u.tsukuba.ac.jp</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Paul Moore writes:<br class="gmail_msg">
<br class="gmail_msg">
> The debate here regarding tuple/frozenset indicates that there may not<br class="gmail_msg">
> be a "standard way" of hashing an iterable (should order matter?).<br class="gmail_msg">
<br class="gmail_msg">
If part of the data structure, yes, if an implementation accident, no.<br class="gmail_msg">
<br class="gmail_msg">
> Although I agree that assuming order matters is a reasonable<br class="gmail_msg">
> assumption to make in the absence of any better information.<br class="gmail_msg">
<br class="gmail_msg">
I don't think so. Eg, with dicts now ordered by insertion, an<br class="gmail_msg">
order-dependent default hash for collections means<br class="gmail_msg">
<br class="gmail_msg">
a = {}<br class="gmail_msg">
b = {}<br class="gmail_msg">
a['1'] = 1<br class="gmail_msg">
a['2'] = 2<br class="gmail_msg">
b['2'] = 2<br class="gmail_msg">
b['1'] = 1<br class="gmail_msg">
hash(a) != hash(b) # modulo usual probability of collision<br class="gmail_msg">
<br class="gmail_msg">
(and modulo normally not hashing mutables). For the same reason I<br class="gmail_msg">
expect I'd disagree with Neil's proposal for an ImmutableWhatever<br class="gmail_msg">
default __hash__ although the hash comparison is "cheap", it's still a<br class="gmail_msg">
pessimization. Haven't thought that through, though.<br class="gmail_msg"></blockquote><div><br></div><div>I don't understand this? How is providing a default method in an abstract base class a pessimization? If it happens to be slower than the code in the current methods, it can still be overridden.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br class="gmail_msg">
BTW, it occurs to me that now that dictionaries are versioned, in some<br class="gmail_msg">
cases it *may* make sense to hash dictionaries even though they are<br class="gmail_msg">
mutable, although the "hash" would need to somehow account for the<br class="gmail_msg">
version changing. Seems messy but maybe someone has an idea?<br class="gmail_msg"></blockquote><div><br></div><div>I think it's important to keep in mind that dictionaries are not versioned in Python. They happen to be versioned in CPython as an unexposed implementation detail. I don't think that such details should have any bearing on potential changes to Python.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br class="gmail_msg">
Steve<br class="gmail_msg">
</blockquote></div></div>