https://github.com/spyoungtech/chunking
tools for chunking iterables
https://github.com/spyoungtech/chunking
Last synced: 6 months ago
JSON representation
tools for chunking iterables
- Host: GitHub
- URL: https://github.com/spyoungtech/chunking
- Owner: spyoungtech
- License: mit
- Archived: true
- Created: 2017-09-13T23:05:07.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2018-02-21T15:11:59.000Z (over 8 years ago)
- Last Synced: 2026-01-05T06:51:47.224Z (6 months ago)
- Language: Python
- Size: 8.79 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# chunking
tools for chunking iterables
Requires Python 3.5+
[](https://travis-ci.org/spyoungtech/chunking)
### Note:
The main reason this package was created was to fill a small gap in [more-itertools](https://github.com/erikrose/more-itertools) for splitting an iterable ON a value (`chunking.split` / `chunking.iter_split`) -- That gap in more-itertools has since been filled with the [addition of `split_at`](https://github.com/erikrose/more-itertools/pull/178).
As such, you should probably just use [more-itertools](https://github.com/erikrose/more-itertools).
## Installation
```
python -m pip install chunking
```
## chunking.chunk
```py
>>> from chunking import chunk
>>> r = range(5)
>>> for c in chunk(r, 2):
... print(c)
...
(0, 1)
(2, 3)
(4,)
```
## chunking.split
```py
>>> from chunking import split
>>> a_list = ["foo", 'bar', 'SEP', 'bacon', 'eggs']
>>> split(a_list, 'SEP')
[['foo', 'bar'], ['bacon', 'eggs']]
```
## chunking.iter_split
Like split, but a generator.
```py
>>> from chunking import iter_split
>>> a_list = ["foo", 'bar', 'SEP', 'bacon', 'eggs']
>>> for c in iter_split(a_list,'SEP'):
... print(c)
...
['foo', 'bar']
['bacon', 'eggs']
```