MCPcopy Index your code
hub / github.com/python/cpython / popitem

Method popitem

Lib/collections/__init__.py:171–192  ·  view source on GitHub ↗

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.

(self, last=True)

Source from the content-addressed store, hash-verified

169 dict.clear(self)
170
171 def popitem(self, last=True):
172 '''Remove and return a (key, value) pair from the dictionary.
173
174 Pairs are returned in LIFO order if last is true or FIFO order if false.
175 '''
176 if not self:
177 raise KeyError('dictionary is empty')
178 root = self.__root
179 if last:
180 link = root.prev
181 link_prev = link.prev
182 link_prev.next = root
183 root.prev = link_prev
184 else:
185 link = root.next
186 link_next = link.next
187 root.next = link_next
188 link_next.prev = root
189 key = link.key
190 del self.__map[key]
191 value = dict.pop(self, key)
192 return key, value
193
194 def move_to_end(self, key, last=True):
195 '''Move an existing element to the end (or beginning if last is false).

Callers 4

test_popitemMethod · 0.95
test_popitem_lastMethod · 0.95
test_issue24348Method · 0.95
test_issue24667Method · 0.95

Calls 1

popMethod · 0.45

Tested by 4

test_popitemMethod · 0.76
test_popitem_lastMethod · 0.76
test_issue24348Method · 0.76
test_issue24667Method · 0.76