mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
Patch #413171: Implement get, setdefault, update in terms of
has_key, __getitem__, and __setitem__.
This commit is contained in:
parent
fa9e273442
commit
f3b30747d6
1 changed files with 7 additions and 5 deletions
|
@ -34,13 +34,15 @@ class UserDict:
|
|||
self.data.update(dict)
|
||||
else:
|
||||
for k, v in dict.items():
|
||||
self.data[k] = v
|
||||
self[k] = v
|
||||
def get(self, key, failobj=None):
|
||||
return self.data.get(key, failobj)
|
||||
if not self.has_key(key):
|
||||
return failobj
|
||||
return self[key]
|
||||
def setdefault(self, key, failobj=None):
|
||||
if not self.data.has_key(key):
|
||||
self.data[key] = failobj
|
||||
return self.data[key]
|
||||
if not self.has_key(key):
|
||||
self[key] = failobj
|
||||
return self[key]
|
||||
def popitem(self):
|
||||
return self.data.popitem()
|
||||
def __contains__(self, key):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue