This release is a pre-release and may not be stable for production use.
ChIter - iterable as a chain
Requirements
- Python 3.7+
Installation
pip install chiter
Documentation
Coming soon
Why?
- Chains do not require saving the intermediate state in temporary variables
- Look more readable
Examples
It is necessary to get the sum of all numbers from the following sequence:"23,45,67\n45,56,55\n\n45,a,5\n-45,56,0"
first way
from itertools import chain
data = "23,45,67\n45,56,55\n\n45,a,5\n-45,56,0"
chunks = (chunk.split(',') for chunk in data.split())
flat_data = chain.from_iterable(chunks)
items = (int(item) for item in flat_data if not item.isalpha())
result = sum(items)
assert result == 352
second way
from itertools import chain
data = "23,45,67\n45,56,55\n\n45,a,5\n-45,56,0"
result = sum((
int(item)
for item in chain.from_iterable(map(lambda c: c.split(','), data.split()))
if not item.isalpha()
))
assert result == 352
chiter way
from chiter import ChIter as I
data = "23,45,67\n45,56,55\n\n45,a,5\n-45,56,0"
result = (I(data.split())
.map(lambda x: x.split(','))
.flat()
.filterfalse(str.isalpha)
.map(int)
.sum())
assert result == 352
Related Libraries
Metadata
Release files for chiter 1.0.0a2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| chiter-1.0.0a2.tar.gz | 4.4 kB | Without provenance | Details for chiter-1.0.0a2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| chiter-1.0.0a2-py3-none-any.whl | Python 3 | none | any | Details for chiter-1.0.0a2-py3-none-any.whl |
Total release size: 9.5 kB
Release files / chiter-1.0.0a2.tar.gz
| Download URL | chiter-1.0.0a2.tar.gz |
|---|---|
| Size | 4.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cdbcb69169cafe78e33a261c2bb3843b8bedcebb79dcd3bea640dc4d4a407880
|
|
BLAKE2b-256 checksum How to use checksums |
0fd5caf2c5532f00822fac5960c42c32ab92bd1351b0113a8821c0228a149cd8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/0.12.16 CPython/3.7.3 Linux/5.0.0-15-generic
|
Release files / chiter-1.0.0a2-py3-none-any.whl
| Download URL | chiter-1.0.0a2-py3-none-any.whl |
|---|---|
| Size | 5.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
56d405513a37ffe12d1b8030d7b2aeb3d9df314e311afb5fd3e8d1fa12100331
|
|
BLAKE2b-256 checksum How to use checksums |
bd99dbeef784bcebe1c27080ac3a39c4b5caaa7fa17fb51eb11c4e7473fa7958
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/0.12.16 CPython/3.7.3 Linux/5.0.0-15-generic
|
Security for chiter 1.0.0a2
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.