Skip to main content
https://img.shields.io/pypi/v/prefsort.svg https://img.shields.io/travis/jonathaneunice/prefsort.svg Documentation Status Updates

Partially sort a sequence, preferring some values.

from prefsort import prefsorted

seq = list('abcde')

seq2 = prefsorted(seq, 'c b')
assert seq2 == ['c', 'b', 'a', 'd', 'e']

Note that this doesn’t sort the majority of the sequence in the way Python’s normal list.sort() or sorted() do. It just pulls the preferred members to the front of the list.

This is particularly handy to have when organizing data columns, for example with pandas, the following will make sure the id and name columns come first in a DataFrame:

df = df.reindex(columns=prefsorted(df.columns, 'id name'))

There is also a reverse parameter that will put the “preferred” items at the end of the list. In this case it’s a “negative preference.”

seq2 = prefsorted(seq, 'c b', reverse=True)
assert seq2 == ['a', 'd', 'e', 'c', 'b']

Metadata

Release files for prefsort 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for prefsort 0.1.0
File Size Uploaded
prefsort-0.1.0.tar.gz 3.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for prefsort 0.1.0
File Interpreter ABI Platform
prefsort-0.1.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 6.9 kB

Release files / prefsort-0.1.0.tar.gz

Download URL prefsort-0.1.0.tar.gz
Size 3.5 kB
Tags Source
SHA-256 checksum
How to use checksums
22c1359cb59bde9c0af494fcd0ac241fd62302b5dfb9f875837ec41f0d2ddf3b
BLAKE2b-256 checksum
How to use checksums
e98a1b7680bb97af5088480a5d539834e7af40553e604f6947310ce870c5bc59
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

Release files / prefsort-0.1.0-py2.py3-none-any.whl

Download URL prefsort-0.1.0-py2.py3-none-any.whl
Size 3.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
b27af30c1ee3ad86402cfffd0721872459d9eb53c06972c9de6fd0b7d4837edb
BLAKE2b-256 checksum
How to use checksums
b7ddc214416c70d68ccebbdf2e7392bd29f3a0c8cb8ffa3726f12ba2448bdb9f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page