Patch #624936: Implement __contains__.

This commit is contained in:
Martin v. Löwis 2002-10-18 08:58:14 +00:00
parent d7bc0fec38
commit e4913c9987
1 changed files with 4 additions and 1 deletions

View File

@ -19,7 +19,7 @@ object):
# such key) # such key)
del d[key] # delete data stored at key (raises KeyError del d[key] # delete data stored at key (raises KeyError
# if no such key) # if no such key)
flag = d.has_key(key) # true if the key exists flag = d.has_key(key) # true if the key exists; same as "key in d"
list = d.keys() # a list of all existing keys (slow!) list = d.keys() # a list of all existing keys (slow!)
d.close() # close it d.close() # close it
@ -61,6 +61,9 @@ class Shelf:
def has_key(self, key): def has_key(self, key):
return self.dict.has_key(key) return self.dict.has_key(key)
def __contains__(self, key):
return self.dict.has_key(key)
def get(self, key, default=None): def get(self, key, default=None):
if self.dict.has_key(key): if self.dict.has_key(key):
return self[key] return self[key]