diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2017-01-24 22:30:04 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2017-01-24 22:30:04 (GMT) |
commit | 78d9e58f204ec4e90502b42c3e7d48dcd76ccb80 (patch) | |
tree | 2e00366df2118cdeef752f6301f80ff118f88833 /Lib/collections | |
parent | 0105606f5531d9a22e672d3d2a72df2c5c447be8 (diff) | |
download | cpython-78d9e58f204ec4e90502b42c3e7d48dcd76ccb80.zip cpython-78d9e58f204ec4e90502b42c3e7d48dcd76ccb80.tar.gz cpython-78d9e58f204ec4e90502b42c3e7d48dcd76ccb80.tar.bz2 |
Issues #29311, #29289: Fixed and improved docstrings for dict and OrderedDict
methods.
Diffstat (limited to 'Lib/collections')
-rw-r--r-- | Lib/collections/__init__.py | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py index 85b4c3c..8408255 100644 --- a/Lib/collections/__init__.py +++ b/Lib/collections/__init__.py @@ -157,9 +157,9 @@ class OrderedDict(dict): dict.clear(self) def popitem(self, last=True): - '''od.popitem() -> (k, v), return and remove a (key, value) pair. - Pairs are returned in LIFO order if last is true or FIFO order if false. + '''Remove and return a (key, value) pair from the dictionary. + Pairs are returned in LIFO order if last is true or FIFO order if false. ''' if not self: raise KeyError('dictionary is empty') @@ -180,11 +180,9 @@ class OrderedDict(dict): return key, value def move_to_end(self, key, last=True): - '''Move an existing element to the end (or beginning if last==False). - - Raises KeyError if the element does not exist. - When last=True, acts like a fast version of self[key]=self.pop(key). + '''Move an existing element to the end (or beginning if last is false). + Raise KeyError if the element does not exist. ''' link = self.__map[key] link_prev = link.prev @@ -248,7 +246,10 @@ class OrderedDict(dict): return default def setdefault(self, key, default=None): - 'od.setdefault(k[,d]) -> od.get(k,d), also set od[k]=d if k not in od' + '''Insert key with a value of default if key is not in the dictionary. + + Return the value for key if key is in the dictionary, else default. + ''' if key in self: return self[key] self[key] = default @@ -274,9 +275,7 @@ class OrderedDict(dict): @classmethod def fromkeys(cls, iterable, value=None): - '''OD.fromkeys(S[, v]) -> New ordered dictionary with keys from S. - If not specified, the value defaults to None. - + '''Create a new ordered dictionary with keys from iterable and values set to value. ''' self = cls() for key in iterable: |