frozendict (v0.1)

Arnaud Delobelle arnodel at gmail.com
Fri Oct 8 02:28:58 EDT 2010


kj <no.email at please.post> writes:

> In <87hbgxlk67.fsf at gmail.com> Arnaud Delobelle <arnodel at gmail.com> writes:
>
>>A simple fix is to use hash(frozenset(self.items())) instead.
>
> Thanks for pointing out the hash bug.  It was an oversight: I meant
> to write
>
>     def __hash__(self):
>         return hash(sorted(tuple(self.items())))

But sorted returns a list!

so you need rather: hash(tuple(sorted(self.items())))

However, it still won't work because some keys may be incomparable.

E.g., try with {1:'a', 1j:'b'}

-- 
Arnaud



More information about the Python-list mailing list