diff options
| author | Jos Verlinde <jos_verlinde@hotmail.com> | 2025-11-06 16:44:40 +0100 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2025-11-26 14:37:58 +1100 |
| commit | 1c47db32e4096c4fdb978771ef108d93bff28ace (patch) | |
| tree | ff6736611ac18e02f556bd087f60da589067329d | |
| parent | 4633d2a0374f79c3306e60b603377606664e8a24 (diff) | |
docs/library: Document OrderedDict.popitem()'s CPython differences.
Fixes issue #18370.
Signed-off-by: Jos Verlinde <jos_verlinde@hotmail.com>
| -rw-r--r-- | docs/library/collections.rst | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/docs/library/collections.rst b/docs/library/collections.rst index 6a23e456c..f973e521e 100644 --- a/docs/library/collections.rst +++ b/docs/library/collections.rst @@ -101,3 +101,19 @@ Classes a 2 w 5 b 3 + + .. method:: OrderedDict.popitem() + + Remove and return a (key, value) pair from the dictionary. + Pairs are returned in LIFO order. + + .. admonition:: Difference to CPython + :class: attention + + ``OrderedDict.popitem()`` does not support the ``last=False`` argument and + will always remove and return the last item if present. + + A workaround for this is to use ``pop(<first_key>)`` to remove the first item:: + + first_key = next(iter(d)) + d.pop(first_key) |
