MCPcopy Index your code
hub / github.com/RustPython/RustPython / popitem

Method popitem

Lib/collections/__init__.py:172–193  ·  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

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