functional approach to work with iterables in python
pip install splitty
You can see examples
from splitty import *
>>> list_to_be_splited = ['spam', 1, 2, 3, 'eggs', 1, 2, 3, 'foo', 1, 2, 3]
>>> split_by = ['spam', 'eggs', 'foo']
>>> splited = find_elements(list_to_be_splited, split_by)
# [(0, 'spam'), (4, 'eggs'), (8, 'foo')]
>>> intervals = make_intervals(splited)
# [slice(0, 4, None), slice(4, 8, None), slice(8, None, None)]
>>> list_with_intervals = apply_intervals(list_to_be_splited, intervals)
# [['spam', 1, 2, 3], ['eggs', 1, 2, 3], ['foo', 1, 2, 3]]
# Alternative sintax to all steps
>>> list_with_intervals = list_by_list(list_to_be_splited, split_by)
# [['spam', 1, 2, 3], ['eggs', 1, 2, 3], ['foo', 1, 2, 3]]
# the same way, but using size for split
>>> chunks(list_to_be_splited, size=4)
# [['spam', 1, 2, 3], ['eggs', 1, 2, 3], ['foo', 1, 2, 3]]
Based on PEP 484 we implement a stub file for mypy using .pyi in splitty.splitty
- Implement documentation
- Write tests using hypotheses
- Lazy alternatives
- File manipulation objects