Skip to main content

An ordered dict with sorting capabilities.

Project description

Keep Dict Sorted

This package contains the ODict class, which is an ordered dict with the capability to keep the items sorted not only in insertion order, but in any order that can be achieved by sorting. Typically this can be sorted on the keys or on the values, but a general sort key function is also possible.


Just a small example, with items sorted on the values:

from keep_dict_sorted import ODict
D = ODict({'a':0, 'c':1, 'b':3, 'd':2}, sortkey='value')
print(D)  # {'a': 0, 'c': 1, 'd': 2, 'b': 3}
# now change a value:
D['c'] = 4
print(D)  # {'a': 0, 'd': 2, 'b': 3, 'c': 4}

For more: see the docstring of the keep_dict_sorted module and the ODict class.


Back in the old times the pyFormex project had its own ordered dict with the capability to sort the items on request. After Python's default dict became ordered, it was dropped from pyFormex as its applications could easily be got with a plane dict and sorting comprehensions. Triggered by a recent discussion on I grabbed the old source, updated it to Python3, added some more functionality (keeping the items sorted at all times, instead of sorting them on request), and threw the whole thing on PyPi. Enjoy.


pyFormex is licensed under the GNU General Public License v3 or later (GPLv3+) and so is this package.

Project details

Release history Release notifications | RSS feed

This version


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

keep-dict-sorted-1.0.tar.gz (16.0 kB view hashes)

Uploaded Source

Built Distribution

keep_dict_sorted-1.0-py3-none-any.whl (16.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page