multicollections.MultiDict stores multiple values for the same key while preserving insertion order. Its API follows multidict, but keys can be of arbitrary hashable types.
With pip:
pip install multicollectionsor conda:
conda install -c conda-forge multicollectionsfrom multicollections import MultiDict
d = MultiDict([("a", 1), ("b", 2), ("a", 3)])
d["a"]
# 1
d.getall("a")
# [1, 3]
list(d.items())
# [("a", 1), ("b", 2), ("a", 3)]
d.add("a", 4)The multicollections.abc module provides abstract base classes for implementing other multi-value collections.
See the documentation for the full API.
