Skip to main content

A data structure to impose a total order on a collection of objects.

Dependencies

ordering requires Python 3.6+. If the type hints were removed, it would probably work in earlier versions, as well.

Usage

An ordering is represented by an Ordering object. The order may be different to the usual order between objects, or even between objects that are not normally comparable.

>>> from ordering import Ordering
>>> order = Ordering([2, 0, 1])

We can then compare the objects in our ordering, to check if the first object comes before the second in the order.

>>> order.compare(0, 1) # 1 after 0
True
>>> order.compare(0, 2) # 2 before 0
False

Our ordering is mutable, and we can add elements on either end, or immediately before or after an existing element.

>>> order.insert_end(3) # Add 3 on the end
>>> order.compare(1, 3) # 3 after 1
True

>>> order.insert_after(0, 4) # Insert 4 immediately after 0
>>> order.compare(0, 4) # 4 after 0
True
>>> order.compare(1, 4) # 4 before 1
False

Orderings are iterable, yielding their items in order.

>>> list(order)
[2, 0, 4, 1, 3]

And can be used as a key in sorting functions, to sort with respect to that order.

>>> sorted(range(3), key=order)
[2, 0, 1]

Metadata

Release files for ordering 0.2.0

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

Built distribution (wheel)

Table of built distributions (wheels) for ordering 0.2.0
File Interpreter ABI Platform
ordering-0.2.0-py3-none-any.whl Python 3 none any Details

Release files / ordering-0.2.0-py3-none-any.whl

Download URL ordering-0.2.0-py3-none-any.whl
Size 5.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cf2920b92605a7c5d9d1060bacc03bf31923ef9ba8d24999b77d662d9f80adcd
BLAKE2b-256 checksum
How to use checksums
08ef853b5fa50d0e5189a2afff95300253f26fd22dbd7ee7f21fed84ae0732be
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for ordering 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

1 release file No provenance

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