[Python-ideas] incremental hashing in __hash__
Steven D'Aprano
steve at pearwood.info
Sat Dec 31 02:00:21 EST 2016
On Fri, Dec 30, 2016 at 07:08:27PM -0800, Ethan Furman wrote:
> So maybe this will work?
>
> def __hash__(self):
> return hash(self.name) * hash(self.nick) * hash(self.color)
I don't like the multiplications. If any of the three hashes return
zero, the overall hash will be zero. I think you need better mixing than
that. Look at tuple:
py> hash((0, 1, 2))
-421559672
py> hash(0) * hash(1) * hash(2)
0
--
Steve
More information about the Python-ideas
mailing list