Shorthand syntax for building OrderedDicts

2.0.2 · active · verified Sat Apr 11

od is a lightweight Python library (version 2.0.2) that provides a shorthand syntax for creating `collections.OrderedDict` instances. It aims to simplify the creation of ordered dictionaries with a concise and readable approach, leveraging Python's flexible syntax to make ordered dictionary construction more intuitive. The library is actively maintained.

Warnings

Install

Imports

Quickstart

The quickstart demonstrates importing the 'od' function and using it to construct a `collections.OrderedDict` with a clean, dictionary-like syntax. It then prints the resulting ordered dictionary and its type, confirming that the order is preserved.

from od import od

# Create an OrderedDict using shorthand syntax
my_ordered_dict = od({
    'first_key': 1,
    'second_key': 2,
    'third_key': 3
})

print(my_ordered_dict)
print(type(my_ordered_dict))

# Verification of order
assert list(my_ordered_dict.keys()) == ['first_key', 'second_key', 'third_key']

view raw JSON →