Collection Methods

collections.OrderedDict.popitem()

Remove and return a key-value pair from the end (default) or the beginning. An empty mapping raises KeyError.

Formal Syntax & Structure

python syntaxpython
mapping.popitem(last=True)

Parameters & Attributes

NameTypeDescription
lastboolSelect the last item when true, first when false.

Return Value

tuple

The tuple result described above.

Working Example

Example Snippetpython
import collectionsd=collections.OrderedDict(a=1,b=2)print(d.popitem(last=False))
Python Reference