Skip to content

Instantly share code, notes, and snippets.

@dw
Created July 15, 2014 00:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dw/77f93efdad9db86012d3 to your computer and use it in GitHub Desktop.
Save dw/77f93efdad9db86012d3 to your computer and use it in GitHub Desktop.
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