frozendict (v0.1)
kj
no.email at please.post
Fri Oct 8 10:02:51 EDT 2010
In <mailman.1461.1286539843.29448.python-list at python.org> "Jonas H." <jonas at lophus.org> writes:
>On 10/08/2010 02:23 AM, kj wrote:
>Here's my implementation suggestion:
>class frozendict(dict):
> def _immutable_error(self, *args, **kwargs):
> raise TypeError("%r object is immutable" % self.__class__.__name__)
> __setitem__ = __delitem__ = clear = pop \
> = popitem = setdefault = update = _immutable_error
> def __hash__(self):
> return hash(frozenset(self.iteritems()))
>Only 9 lines :-)
Thanks, you just answered the question I just posted, while I was
still writing it!
~kj
More information about the Python-list
mailing list