[issue34751] Hash collisions for tuples
Jeroen Demeyer
report at bugs.python.org
Mon Sep 24 05:52:53 EDT 2018
Jeroen Demeyer <J.Demeyer at UGent.be> added the comment:
While writing up the analysis above, it occurred to me that collisions already happen for 2-tuples:
>>> hash((3, -2)) == hash((-3, 0))
True
These kind of 2-tuples of small integers don't look contrived at all. I can easily see them appearing, in mathematical applications for example.
As for real-world usage: the only thing that I can say is that I discovered these hash collisions a while ago, while working on SageMath. I was testing the hash for a custom class and I found collisions, which I traced back to collisions for tuples.
In any case, it is hard to find real-world problems where a bad hash really matters, since Python works fine with a broken hash too.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34751>
_______________________________________
More information about the Python-bugs-list
mailing list