Sorted containers
Contrary to its name, this package does not really help you to efficiently sort your data, - you may use built-in tools of Python, numpy or pandas for that purpose.
This tool, however, allows you to declare that certain container is already sorted and, based on that information, perform certain operations on such containers more efficiently.
Supported operations
- Merge two or more sorted iterators into one magnificent sorted iterator
- Subtract one sorted iterator from another, returning an iterator which yields all items that exist in the latter but not in the first
- Deduplicate a sorted iterator
Examples
from itertools import count, islice
from sorted import Sorted, merge
# Merge
print(list(Sorted([0, 2, 4]) + Sorted([1, 3, 5])))
# [0, 1, 2, 3, 4, 5]
# Subtract
natural_numbers = Sorted(count())
even_numbers = Sorted(filter(lambda i: i % 2 == 0, count()))
odd_numbers = natural_numbers - even_numbers
print(list(islice(odd_numbers, 5)))
# [1, 3, 5, 7, 9]
# Deduplicate
iterators = [
Sorted((0, ) * 50),
Sorted((5, ) * 50),
Sorted(count(25))
]
list(islice(
merge(*iterators).unique(),
4
))
# [0, 5, 25, 26]
To perform these operations, sorted uses lazy iterative algorithms with linear complexity by time and constant complexity by RAM.
Metadata
Release files for sorted 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| sorted-0.1.0.tar.gz | 3.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sorted-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.9 kB
Release files / sorted-0.1.0.tar.gz
| Download URL | sorted-0.1.0.tar.gz |
|---|---|
| Size | 3.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1bf5539a3c4216a7798b026e45d5d9e153dc7b19719b6645d91e7f2efaa27228
|
|
BLAKE2b-256 checksum How to use checksums |
52350607ac2246415a24dfc3a91136f8b6ccb2575c0a92a3e9c05df5003faa1d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.5rc1
|
Release files / sorted-0.1.0-py3-none-any.whl
| Download URL | sorted-0.1.0-py3-none-any.whl |
|---|---|
| Size | 5.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5e3f19dd1e4fdf2a9c3c43800f8cdb7eb9eb3beb132b679fa4499228d9e0312f
|
|
BLAKE2b-256 checksum How to use checksums |
15552696d4a55a22f0387bfb95f05a930cdc6e45d0a12e6ccb09a25d9d8bfad3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.5rc1
|