OrderedDict (Python 2.x Backport)

1.1 · abandoned · verified Thu Apr 16

The 'ordereddict' library provides a backport of the `collections.OrderedDict` class, originally introduced in Python 2.7 and 3.1, for use in older Python 2.x environments (specifically Python 2.4, 2.5, and 2.6). It enables maintaining the insertion order of keys in a dictionary-like structure. This package is no longer maintained and serves only historical compatibility purposes for very old Python 2 projects.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates importing and using the `OrderedDict` class from the backport for Python 2.4-2.6. It includes a version check to highlight the library's specific compatibility window.

import sys

# This library is for Python 2.x <= 2.6
# For Python 2.7+ or 3.x, use 'from collections import OrderedDict'

if sys.version_info < (2, 7) and sys.version_info >= (2, 4):
    from ordereddict import OrderedDict
    print("Using ordereddict backport")
    od = OrderedDict()
    od['first'] = 1
    od['second'] = 2
    od['third'] = 3
    print(od.items())
else:
    print("This library is not needed for your Python version.")
    print("Use 'from collections import OrderedDict' instead.")

view raw JSON →