Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cthoyt/multisplitby
Split an iterable into multiple using arbitrary predicates.
https://github.com/cthoyt/multisplitby
Last synced: about 1 month ago
JSON representation
Split an iterable into multiple using arbitrary predicates.
- Host: GitHub
- URL: https://github.com/cthoyt/multisplitby
- Owner: cthoyt
- License: mit
- Created: 2018-10-28T17:26:55.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-01-05T21:47:15.000Z (almost 6 years ago)
- Last Synced: 2024-09-16T23:13:28.472Z (about 2 months ago)
- Language: Python
- Homepage:
- Size: 24.4 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
multisplitby |build| |coverage| |zenodo|
========================================
Split an iterable into multiple using arbitrary predicates.This package comes with a single function: ``multisplitby.multi_split_by``.
For all lists ``values`` and ``predicates``, the following conditions are always true:
1. ``1 + len(predicates) = len(list(multi_split_by(values, predicates)))``
2. ``values == itertools.chain.from_iterable(multi_split_by(values, predicates))``Normal usage with one predicate:
.. code-block:: python
>>> values = range(4)
>>> predicates = [lambda x: 2 < x]
>>> list(map(list, multi_split_by(values, predicates)))
[[0, 1, 2], [3]]Normal usage with several predicates:
.. code-block:: python
>>> values = range(9)
>>> predicates = [lambda x: 2 < x, lambda x: 4 < x, lambda x: 7 < x]
>>> list(map(list, multi_split_by(values, predicates)))
[[0, 1, 2], [3, 4], [5, 6, 7], [8]]If no values are given, will result in ``|predicates| + 1`` generators, all yielding empty lists.
.. code-block:: python
>>> values = []
>>> predicates = [lambda x: 2 < x, lambda x: 4 < x, lambda x: 7 < x]
>>> list(map(list, multi_split_by(values, predicates)))
[[], [], [], []]If no predicates are given, will result in a single generator that yields the original list:
.. code-block:: python
>>> values = range(4)
>>> predicates = []
>>> list(map(list, multi_split_by(values, predicates)))
[[0, 1, 2, 3]]Installation |pypi_version| |python_versions| |pypi_license|
------------------------------------------------------------
Install from `PyPI `_ with:.. code-block:: bash
$ pip install multisplitby
or get the latest code from `GitHub `_ with:
.. code-block:: bash
$ git clone https://github.com/cthoyt/multisplitby.git
$ cd multisplitby
$ pip install -e ... |build| image:: https://travis-ci.com/cthoyt/multisplitby.svg?branch=master
:target: https://travis-ci.com/cthoyt/multisplitby.. |coverage| image:: https://codecov.io/gh/cthoyt/multisplitby/branch/master/graph/badge.svg
:target: https://codecov.io/gh/cthoyt/multisplitby.. |python_versions| image:: https://img.shields.io/pypi/pyversions/multisplitby.svg
:alt: Stable Supported Python Versions.. |pypi_version| image:: https://img.shields.io/pypi/v/multisplitby.svg
:alt: Current version on PyPI.. |pypi_license| image:: https://img.shields.io/pypi/l/multisplitby.svg
:alt: Apache 2.0 License.. |zenodo| image:: https://zenodo.org/badge/155096674.svg
:target: https://zenodo.org/badge/latestdoi/155096674