Skip to content

Commit 1c47db3

Browse files
Josverldpgeorge
authored andcommitted
docs/library: Document OrderedDict.popitem()'s CPython differences.
Fixes issue micropython#18370. Signed-off-by: Jos Verlinde <jos_verlinde@hotmail.com>
1 parent 4633d2a commit 1c47db3

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

docs/library/collections.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,19 @@ Classes
101101
a 2
102102
w 5
103103
b 3
104+
105+
.. method:: OrderedDict.popitem()
106+
107+
Remove and return a (key, value) pair from the dictionary.
108+
Pairs are returned in LIFO order.
109+
110+
.. admonition:: Difference to CPython
111+
:class: attention
112+
113+
``OrderedDict.popitem()`` does not support the ``last=False`` argument and
114+
will always remove and return the last item if present.
115+
116+
A workaround for this is to use ``pop(<first_key>)`` to remove the first item::
117+
118+
first_key = next(iter(d))
119+
d.pop(first_key)

0 commit comments

Comments
 (0)