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.
Documentation
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.
History
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 discuss.python.org 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.
License
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
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for keep_dict_sorted-1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa478c0e47ec7d2f864e3576bf0e84ee4e0ad0ca2409ad8c1b323e2e6d6aec9a |
|
MD5 | fd1d517d61651a0d4f846813a1d5b20c |
|
BLAKE2b-256 | c412b7ee06d647b7eee2917088980004f294dbaaf390cb085a4677bfa3109e2d |