A small utility for sorting lists of dictionaries by dictionary key
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
keysort
.gitignore
.travis.yml
CHANGELOG.md
CODE_OF_CONDUCT.md
LICENSE
README.rst
setup.py
tests.py

README.rst

Keysort: Sorting Lists of Dictionaries

Keysort is small utility for sorting lists of dictionaries by dictionary key.

https://travis-ci.org/nkantar/Keysort.svg?branch=master

Examples

>>> from keysort import keysort
>>> my_list = [{'code': 'beta',    'number': 3},
               {'code': 'delta',   'number': 2},
               {'code': 'alpha',   'number': 0},
               {'code': 'beta',    'number': 2},
               {'code': 'charlie', 'number': 1}]
>>> keysort(my_list, ['code', 'number'])
[{'code': 'alpha',   'number': 0},
 {'code': 'beta',    'number': 2},
 {'code': 'beta',    'number': 3},
 {'code': 'charlie', 'number': 1},
 {'code': 'delta',   'number': 2}]
>>> keysort(my_list, ['number', 'code'])
[{'code': 'alpha',   'number': 0},
 {'code': 'charlie', 'number': 1},
 {'code': 'beta',    'number': 2},
 {'code': 'delta',   'number': 2},
 {'code': 'beta',    'number': 3}]

Install

pip install keysort

Contributing

Contributions of all sorts are welcome, be they bug reports, patches, or even just feedback. Creating a new issue or pull request is probably the best way to get started.

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.