frozendict (v0.1)

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Thu Oct 7 20:31:56 EDT 2010


On Fri, 08 Oct 2010 00:23:30 +0000, kj wrote:

> 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())))
> 
> I imagine that frozenset is better than sorted(tuple(...)) here, but
> it's not obvious to me why.


Because it's always better to use a well-written, fast, efficient, 
correct, well-tested wheel than to invent your own slow, incorrect 
wheel :)



-- 
Steven



More information about the Python-list mailing list