Skip to main content

Sort list by multiple keys and directions

Project description

mangosort: Sort list by multiple keys and directions

mangosort is a small module that helps you sort lists of dictionaries by multiple keys

Build Status Build status

Hot to use

Sort by multiple directions:

To sort by different directions at same time you need to pass a list of dictionaries with keys you want to order and values asc or desc.

from mangosort import mangosort

my_list =  [{'code': 'beta', 'number': 3}, 
            {'code': 'delta', 'number': 2},
            {'code': 'delta', 'number': 3}]

mangosort.sort_by_key(my_list, [{'code': 'desc'}, {'number': 'asc'}])

[{'code': 'delta', 'number': 2}, 
{'code': 'delta', 'number': 3}, 
{'code': 'beta', 'number': 3}]

If you need or prefer to pass bool, in this case, think reverse True(desc) or False(asc).

# Reverse True or False
mangosort.sort_by_key(my_list, [{'code': True}, {'number': 0}])

[{'code': 'delta', 'number': 2}, 
{'code': 'delta', 'number': 3}, 
{'code': 'beta', 'number': 3}]

Sort ASC:

from mangosort import mangosort

my_list =  [{'code': 'beta', 'number': 3}, 
            {'code': 'delta', 'number': 2},
            {'code': 'delta', 'number': 3}]
mangosort.sort_by_key_asc(my_list, ['code', 'number'])

[{'code': 'beta', 'number': 3}, 
{'code': 'delta', 'number': 2}, 
{'code': 'delta', 'number': 3}]

Sort DESC:

from mangosort import mangosort

my_list =  [{'code': 'beta', 'number': 3}, 
            {'code': 'delta', 'number': 2},
            {'code': 'delta', 'number': 3}]
mangosort.sort_by_key_asc(my_list, ['code', 'number'])

[{'code': 'delta', 'number': 3}, 
{'code': 'delta', 'number': 2}, 
{'code': 'beta', 'number': 3}]

How to Install

Install via PyPi

pip install mangosort

Contributing

I’m accepting pull requests that improve speed and legibility of the code or anything else you think will be good.

License

This module is under MIT License, but you can do what you want. It's just a bunch of code.

Just tell your friends about it.

Communism will win!

Communism will win!

Project details


Download files

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

Source Distribution

mangosort-0.2.1.tar.gz (2.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mangosort-0.2.1-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file mangosort-0.2.1.tar.gz.

File metadata

  • Download URL: mangosort-0.2.1.tar.gz
  • Upload date:
  • Size: 2.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.7

File hashes

Hashes for mangosort-0.2.1.tar.gz
Algorithm Hash digest
SHA256 9bebe00f5a9fc7bec11471fbc188b7a3427ca06fa7ccb01a66e4b38daccfa9d9
MD5 14b62d973e7dbbde42a2e06187c0fcc3
BLAKE2b-256 31a4eaa9f0bbcf427955a4282ed9f7c1aee9f78f8b23352b8ef34b5a5c07182d

See more details on using hashes here.

File details

Details for the file mangosort-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: mangosort-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.7

File hashes

Hashes for mangosort-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7c66e242136d89ee3b76bf4ef7e3c5008b32dbaa91df737fb77bf8ee6f590363
MD5 faed9e3b70d7745865b98afee03e97ac
BLAKE2b-256 96c143d8ad76418aba934deafb528b0126332c480fa7471e822e448069c8f2b4

See more details on using hashes here.

Supported by

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