Skip to content

Instantly share code, notes, and snippets.

Embed
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)
self.data = types.MappingProxyType(d)
self._h = sum(map(hash, self.data.items()))
__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