diff options
author | Eeo Jun <packwolf58@gmail.com> | 2016-04-27 20:21:40 +0800 |
---|---|---|
committer | Eeo Jun <packwolf58@gmail.com> | 2016-04-27 20:21:40 +0800 |
commit | 18e095cd0ed350e7ce5ee548340a42eadaeffb95 (patch) | |
tree | 226e74bc52c29fcaccdc101ed833c10649c69a03 | |
parent | 1bcc5d3a6466144011c7afcaf21bd5dc83568952 (diff) |
More efficient __contains__
-rw-r--r-- | frozendict/__init__.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/frozendict/__init__.py b/frozendict/__init__.py index 7036731..9598f10 100644 --- a/frozendict/__init__.py +++ b/frozendict/__init__.py @@ -12,6 +12,9 @@ class frozendict(collections.Mapping): def __getitem__(self, key): return self.__dict[key] + def __contains__(self, key): + return key in self.__dict + def copy(self, **add_or_replace): return frozendict(self, **add_or_replace) @@ -45,6 +48,9 @@ class FrozenOrderedDict(collections.Mapping): def __getitem__(self, key): return self.__dict[key] + def __contains__(self, key): + return key in self.__dict + def copy(self, **add_or_replace): return FrozenOrderedDict(self, **add_or_replace) |