Created
July 15, 2014 00:44
-
-
Save dw/77f93efdad9db86012d3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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