Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import collections, types
class frozendict(collections.UserDict):
def __init__(self, d=None, **kw):
d = kw if d is None else dict(d, **kw) = types.MappingProxyType(d)
self._h = sum(map(hash,
__hash__ = lambda self: self._h
__repr__ = lambda self: repr(dict(self))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment