ID EN
Collections

OrderedDict

Python 3.11

Return an instance of a dict subclass that has methods specialized for rearranging dictionary order.

Syntax

PYTHON
class collections.OrderedDict([items])

Examples

Example 1
PYTHON
>>> d = OrderedDict.fromkeys('abcde')
>>> d.move_to_end('b')
>>> ''.join(d)
'acdeb'
>>> d.move_to_end('b', last=False)
>>> ''.join(d)
'bacde'

See Also

dict popitem() KeyError