@@ -28,20 +28,20 @@ class OrderedDict(dict):
2828 # An inherited dict maps keys to values.
2929 # The inherited dict provides __getitem__, __len__, __contains__, and get.
3030 # The remaining methods are order-aware.
31- # Big-O running times for all methods are the same as for regular dictionaries.
31+ # Big-O running times for all methods are the same as regular dictionaries.
3232
33- # The internal self.__map dictionary maps keys to links in a doubly linked list.
33+ # The internal self.__map dict maps keys to links in a doubly linked list.
3434 # The circular doubly linked list starts and ends with a sentinel element.
3535 # The sentinel element never gets deleted (this simplifies the algorithm).
36- # The sentinel is stored in self.__hardroot with a weakref proxy in self.__root.
36+ # The sentinel is in self.__hardroot with a weakref proxy in self.__root.
3737 # The prev/next links are weakref proxies (to prevent circular references).
3838 # Individual links are kept alive by the hard reference in self.__map.
3939 # Those hard references disappear when a key is deleted from an OrderedDict.
4040
4141 def __init__ (self , * args , ** kwds ):
42- '''Initialize an ordered dictionary. Signature is the same as for
43- regular dictionaries, but keyword arguments are not recommended
44- because their insertion order is arbitrary.
42+ '''Initialize an ordered dictionary. The signature is the same as
43+ regular dictionaries, but keyword arguments are not recommended because
44+ their insertion order is arbitrary.
4545
4646 '''
4747 if len (args ) > 1 :
@@ -58,8 +58,8 @@ def __init__(self, *args, **kwds):
5858 def __setitem__ (self , key , value ,
5959 dict_setitem = dict .__setitem__ , proxy = _proxy , Link = _Link ):
6060 'od.__setitem__(i, y) <==> od[i]=y'
61- # Setting a new item creates a new link which goes at the end of the linked
62- # list, and the inherited dictionary is updated with the new key/value pair.
61+ # Setting a new item creates a new link at the end of the linked list,
62+ # and the inherited dictionary is updated with the new key/value pair.
6363 if key not in self :
6464 self .__map [key ] = link = Link ()
6565 root = self .__root
@@ -71,8 +71,8 @@ def __setitem__(self, key, value,
7171
7272 def __delitem__ (self , key , dict_delitem = dict .__delitem__ ):
7373 'od.__delitem__(y) <==> del od[y]'
74- # Deleting an existing item uses self.__map to find the link which is
75- # then removed by updating the links in the predecessor and successor nodes.
74+ # Deleting an existing item uses self.__map to find the link which gets
75+ # removed by updating the links in the predecessor and successor nodes.
7676 dict_delitem (self , key )
7777 link = self .__map .pop (key )
7878 link_prev = link .prev
@@ -170,6 +170,11 @@ def __sizeof__(self):
170170 __marker = object ()
171171
172172 def pop (self , key , default = __marker ):
173+ '''od.pop(k[,d]) -> v, remove specified key and return the corresponding
174+ value. If key is not found, d is returned if given, otherwise KeyError
175+ is raised.
176+
177+ '''
173178 if key in self :
174179 result = self [key ]
175180 del self [key ]
@@ -179,7 +184,7 @@ def pop(self, key, default=__marker):
179184 return default
180185
181186 def setdefault (self , key , default = None ):
182- 'OD .setdefault(k[,d]) -> OD .get(k,d), also set OD [k]=d if k not in OD '
187+ 'od .setdefault(k[,d]) -> od .get(k,d), also set od [k]=d if k not in od '
183188 if key in self :
184189 return self [key ]
185190 self [key ] = default
@@ -208,14 +213,14 @@ def copy(self):
208213
209214 @classmethod
210215 def fromkeys (cls , iterable , value = None ):
211- '''OD.fromkeys(S[, v]) -> New ordered dictionary with keys from S
212- and values equal to v (which defaults to None) .
216+ '''OD.fromkeys(S[, v]) -> New ordered dictionary with keys from S.
217+ If not specified, the value defaults to None.
213218
214219 '''
215- d = cls ()
220+ self = cls ()
216221 for key in iterable :
217- d [key ] = value
218- return d
222+ self [key ] = value
223+ return self
219224
220225 def __eq__ (self , other ):
221226 '''od.__eq__(y) <==> od==y. Comparison to another OD is order-sensitive
0 commit comments