Skip to main content

Merge, subtract, deduplicate and otherwise manipulate Python iterators that are known to be sorted.

Project description

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.

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

sorted-0.1.0.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

sorted-0.1.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file sorted-0.1.0.tar.gz.

File metadata

  • Download URL: sorted-0.1.0.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for sorted-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1bf5539a3c4216a7798b026e45d5d9e153dc7b19719b6645d91e7f2efaa27228
MD5 b38facac1d7db9b8b15e1d956cfa5119
BLAKE2b-256 52350607ac2246415a24dfc3a91136f8b6ccb2575c0a92a3e9c05df5003faa1d

See more details on using hashes here.

File details

Details for the file sorted-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: sorted-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for sorted-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5e3f19dd1e4fdf2a9c3c43800f8cdb7eb9eb3beb132b679fa4499228d9e0312f
MD5 4d2a4789f19915d892d383b4f7a32b64
BLAKE2b-256 15552696d4a55a22f0387bfb95f05a930cdc6e45d0a12e6ccb09a25d9d8bfad3

See more details on using hashes here.

Supported by

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