<commit_before>==============
More Itertools
==============

.. image:: https://coveralls.io/repos/github/erikrose/more-itertools/badge.svg?branch=master
  :target: https://coveralls.io/github/erikrose/more-itertools?branch=master

Python's ``itertools`` library is a gem - you can compose elegant solutions
for a variety of problems with the functions it provides. In ``more-itertools``
we collect additional building blocks, recipes, and routines for working with
Python iterables.

Getting started
===============

To get started, install the library with `pip <https://pip.pypa.io/en/stable/>`_:

.. code-block:: shell

    pip install more-itertools

The recipes from the `itertools docs <https://docs.python.org/3/library/itertools.html#itertools-recipes>`_
are included in the top-level package:

.. code-block:: python

    >>> from more_itertools import flatten
    >>> iterable = [(0, 1), (2, 3)]
    >>> list(flatten(iterable))
    [0, 1, 2, 3]

Several new recipes are available as well:

.. code-block:: python

    >>> from more_itertools import chunked
    >>> iterable = [0, 1, 2, 3, 4, 5, 6, 7, 8]<commit_msg>Overview Table for Readme with links to API<commit_after>==============
More Itertools
==============

.. image:: https://coveralls.io/repos/github/erikrose/more-itertools/badge.svg?branch=master
  :target: https://coveralls.io/github/erikrose/more-itertools?branch=master

Python's ``itertools`` library is a gem - you can compose elegant solutions
for a variety of problems with the functions it provides. In ``more-itertools``
we collect additional building blocks, recipes, and routines for working with
Python iterables.

====================== ========================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================
              Grouping                                                                                                                                                                                                                                                                                                       `bucket <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.bucket>`_, `chunked <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.chunked>`_, `distribute <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.distribute>`_, `divide <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.divide>`_, `grouper <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.grouper>`_, `partition <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.partition>`_, `sliced <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.sliced>`_, `split_after <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.split_after>`_, `split_at <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.split_at>`_, `split_before <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.split_before>`_
Lookahead and lookback                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     `peekable <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.peekable>`_, `seekable <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.seekable>`_, `spy <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.spy>`_
             Windowing                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             `pairwise <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.pairwise>`_, `stagger <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.stagger>`_, `windowed <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.windowed>`_
            Augmenting                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     `adjacent <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.adjacent>`_, `count_cycle <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.count_cycle>`_, `groupby_transform <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.groupby_transform>`_, `intersperse <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.intersperse>`_, `ncycles <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.ncycles>`_, `padded <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.padded>`_, `padnone <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.padnone>`_
             Combining                                                                                                                                                                                                                                                                   `collapse <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.collapse>`_, `collate <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.collate>`_, `dotproduct <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.dotproduct>`_, `flatten <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.flatten>`_, `interleave <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.interleave>`_, `interleave_longest <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.interleave_longest>`_, `prepend <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.prepend>`_, `roundrobin <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.roundrobin>`_, `sort_together <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.sort_together>`_, `zip_offset <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.zip_offset>`_
           Summarizing `all_equal <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.all_equal>`_, `consecutive_groups <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.consecutive_groups>`_, `exactly_n <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.exactly_n>`_, `first <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.first>`_, `first_true <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.first_true>`_, `ilen <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.ilen>`_, `locate <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.locate>`_, `map_reduce <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.map_reduce>`_, `nth <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.nth>`_, `one <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.one>`_, `quantify <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.quantify>`_, `run_length <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.run_length>`_, `unique_to_each <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.unique_to_each>`_
             Selecting                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               `islice_extended <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.islice_extended>`_, `lstrip <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.lstrip>`_, `rstrip <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.rstrip>`_, `strip <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.strip>`_, `tail <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.tail>`_, `take <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.take>`_, `unique_everseen <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.unique_everseen>`_, `unique_justseen <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.unique_justseen>`_
         Combinatorics                                                                                                                                                                                                                                                                                                                                           `circular_shifts <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.circular_shifts>`_, `distinct_permutations <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.distinct_permutations>`_, `nth_combination <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.nth_combination>`_, `powerset <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.powerset>`_, `random_combination <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.random_combination>`_, `random_combination_with_replacement <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.random_combination_with_replacement>`_, `random_permutation <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.random_permutation>`_, `random_product <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.random_product>`_
              Wrapping                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     `always_iterable <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.always_iterable>`_, `consumer <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.consumer>`_, `iter_except <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.iter_except>`_, `with_iter <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.with_iter>`_
                Others                                                                                                                                             `SequenceView <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.SequenceView>`_, `accumulate <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.accumulate>`_, `always_reversible <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.always_reversible>`_, `consume <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.consume>`_, `difference <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.difference>`_, `iterate <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.iterate>`_, `make_decorator <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.make_decorator>`_, `numeric_range <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.numeric_range>`_, `repeatfunc <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.repeatfunc>`_, `side_effect <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.side_effect>`_, `tabulate <https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.tabulate>`_
====================== ========================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

Getting started
===============

To get started, install the library with `pip <https://pip.pypa.io/en/stable/>`_:

.. code-block:: shell

    pip install more-itertools

The recipes from the `itertools docs <https://docs.python.org/3/library/itertools.html#itertools-recipes>`_
are included in the top-level package:

.. code-block:: python

    >>> from more_itertools import flatten
    >>> iterable = [(0, 1), (2, 3)]
    >>> list(flatten(iterable))
    [0, 1, 2, 3]

Several new recipes are available as well:

.. code-block:: python

    >>> from more_itertools import chunked
    >>> iterable = [0, 1, 2, 3, 4, 5, 6, 7, 8]
{'fraction_non_alphanumeric': 0.2392450263560619, 'fraction_numerical': 0.0020404693079408265, 'mean_word_length': 1.7724701445631679, 'pattern_counts': {'":': 0, '<': 84, '<?xml version=': 0, '>': 114, 'https://': 85, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 237, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6105926', 'n_tokens_mistral': 3944, 'n_tokens_neox': 3749, 'n_words': 394}