Find out what happens in ICS calendar files - query and filter RFC 5545 compatible .ics files for events, journals, TODOs and more.
Project description
sorted_chain
itertools.chain with sorted result
Installation
You can install sorted_chain
from PyPI:
pip install sorted_chain
Usage
You can pass any amount of iterators of sorted values to sorted_chain()
.
The result will be sorted, then.
>>> from sorted_chain import sorted_chain, IterableIsNotSorted
>>> list(sorted_chain([1, 3, 5], [2, 4, 6]))
[1, 2, 3, 4, 5, 6]
The input iterables must be sorted! Otherwise you will receive a IterableIsNotSorted
exception.
>>> from sorted_chain import IterableIsNotSorted
>>> try:
... list(sorted_chain([1000, 0])) # wrong order
... except IterableIsNotSorted:
... print("error!")
error!
Iterators can also be in decending order:
>>> list(sorted_chain([100, 10, 1], [99, 9, -1], reverse=True))
[100, 99, 10, 9, 1, -1]
The input can be generators. Their values are only retrieved when needed.
>>> large_generator1 = iter(range(1000))
>>> large_generator2 = iter(range(1000))
>>> for value in sorted_chain(large_generator1, large_generator2):
... if value >= 100:
... break
>>> next(large_generator1) # this generator had reached 100
101
>>> next(large_generator2) # this generator was not used, yet
101
If you have elements that you would like to sort with a key, you can do that as expected:
>>> positive = [1, 3, 5]
>>> negative = [-2, -4, -6]
>>> list(sorted_chain(positive, negative, key=lambda x: x*x)) # sort without minus
[1, -2, 3, -4, 5, -6]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
sorted_chain-0.0.1.dev8.tar.gz
(27.2 kB
view hashes)
Built Distribution
Close
Hashes for sorted_chain-0.0.1.dev8-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c3f88e17b5b9e0f5f11da632047aea3599ce41e8e2c6b3f9585418d0d1c223b |
|
MD5 | 79dfd754ef1b607c0c9c20f27fa0a0eb |
|
BLAKE2b-256 | a41a7dba6a4947ff392a6a31921b5e1923ce978606c72bdf923b22767d79dd2d |