On this page
  1. collections.OrderedDict
  2. Import
  3. Signature & Overview
  4. Methods & Attributes
  5. Usage
  6. Gotchas
  7. REPL Inspect

collections.OrderedDict

Prev: collections.namedtuple | Up: collections | Next: collections.UserDict
Rel: collections.ChainMap, collections.Counter, collections.defaultdict, collections.deque
Ref: docs.python.org — collections.OrderedDict
Tags: #public #python3 #stdlib #collections


Import

import collections
from collections import OrderedDict

Signature & Overview

collections.OrderedDict(...)

Dictionary that remembers insertion order

Methods & Attributes

Usage

from collections import OrderedDict

od = OrderedDict([("a", 1), ("b", 2), ("c", 3)])
od.move_to_end("a")                 # move to right end
assert list(od) == ["b", "c", "a"]
assert od.popitem(last=False) == ("b", 2)   # FIFO pop from left

Gotchas

REPL Inspect

from collections import OrderedDict
help(OrderedDict)

Linked from

Related notes