witertools.
witertools provides:
- functions that take a function that returns and iterator, and return a function that returns list.
- wrappers around built in functions that return iterators (filter, map, and zip)
- wrappers around the functions in itertools except count, cycle, and repeat
- wrappers around the functions in more_itertools
The motivation as that itertools and more-itertools in particular have functions that return iterators, but very frequently the desired result is a list. Over and over in code you will see repeated code of calling list on the result of a function that produces an interator. You will even see it in most examples in the more-itertools api.
Wrappers Around Functions that Return Iterators
In witertools: iterator_to_list_function will take a function that returns an iterable, and return a function that returns a list.
>>> from witertools import *
>>> f=iterator_to_list_function(filter)
>>> w.filter(lambda s: True, [3,4,5])
[3, 4, 5]
iterator_name_to_list_function will take a module object and a function name, and return a function that returns a list.
>> g=iterator_name_to_list_function(__builtins__,"filter")
>>> g(lambda s : True , [1,2])
[1, 2]
Wrappers Around Built in Functions
To use a wrapper around a built in function, just use a function from the same name from the witertools package.
>>> import witertools as w
>>> w.filter(lambda s: True, [3,4,5])
[3, 4, 5]
which replaces
[3, 4, 5]
Wrappers Around itertools
Use a function from the witertools.itertools namespace, with the same name as the function in the itertools namespace.
>>> i.chain([1,3],[4,5])
[1, 3, 4, 5]
Wrappers Around more-itertools
Use a function from the witertools.more_itertools namespace, with the same name as the function in the more-itertools namespace. You will need to install more-itertools to use these functions, as more-itertools as not a prequisite of witertools.
>>> from witertools.more_itertools import chunked
>>> chunked([1, 2, 3, 4, 5, 6], 3)
[[1, 2, 3], [4, 5, 6]]
There are a few functions in more_itertools that do not return iterables. For example, nth_or_last. These functions are still wrapped in witertools.more_itertools but will result in a traceback.
>>> from witertools.more_itertools import nth_or_last
>>> nth_or_last([0, 1, 2, 3], 2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Program Files (x86)\Python39-32\lib\site-packages\witertools\iterator_to_list.py", line 7, in as_list
return list(iterator_function(*args,**kwargs))
TypeError: 'int' object is not iterable
Metadata
Release files for witertools 1.0.1
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 |
|---|---|---|---|---|
| witertools-1.0.1.tar.gz | 5.0 kB | Without provenance | Details for witertools-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| witertools-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for witertools-1.0.1-py3-none-any.whl |
Total release size: 9.7 kB
Release files / witertools-1.0.1.tar.gz
| Download URL | witertools-1.0.1.tar.gz |
|---|---|
| Size | 5.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b8028d28d1ac4534488ba9d3a52404f1c890f4756d8b06eb6371b6f881a8fc05
|
|
BLAKE2b-256 checksum How to use checksums |
5b639114fd678f661bf304bd73a42bbd1231c38158234613a734d45bb180d3dc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.27.1
|
Release files / witertools-1.0.1-py3-none-any.whl
| Download URL | witertools-1.0.1-py3-none-any.whl |
|---|---|
| Size | 4.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
52ec188b7e7f1959cc70020031aeecf8368b05366b06cd952c90793df8e91795
|
|
BLAKE2b-256 checksum How to use checksums |
77b6087cc67da5365ca1ad48988697501ba6d77173cd88ef6bfbfde5798d7482
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.27.1
|
Security for witertools 1.0.1
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.