Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • A awesome-python
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 13
    • Issues 13
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 317
    • Merge requests 317
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Vinta Chen
  • awesome-python
  • Merge requests
  • !1470

add more-itertools

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/ptosi/master into master Feb 07, 2020
  • Overview 1
  • Commits 1
  • Pipelines 0
  • Changes 1

Created by: ptosi

What is this Python project?

From the README of the project:

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.

What's the difference between this Python project and similar ones?

more-itertools provides most re-usable functions one would want when working with iterables. By relying on this lightweight package, similarly to what itertools provide, one can write more readable and maintainable code, while avoiding having to re-invent the wheel (and introducing bugs by doing so).

As simple examples, instead of using raw iterators, one should use itertools when appropriate:

>>> from itertools import repeat

>>> (10 for _ in range(3))  # Instead of this ...
>>> repeat(10, 3)           # ... use that!

and more-itertools is based on the same idea and provides many more building blocks:

>>> from more_itertools import ilen

>>> sum(1 for _ in iter)  # Instead of this ...
>>> ilen(iter)            # ... use that!

Of course, the project also provides more advanced expressions, hard to express as one-liners. Some of my favourites (notice their high-quality documentation):

  • all_equal(iterable)
  • last(iterable[, default])
  • nth(iterable, n, default=None)
  • consume(iterator, n=None)
  • distribute(n, iterable)
  • roundrobin(*iterables)
  • windowed(seq, n, fillvalue=None, step=1)
  • substrings(iterable)
  • powerset(iterable)
  • random_permutation(iterable, r=None)
  • with_iter(context_manager)

In many cases where I wondered "Why didn't they implement this in itertools?!", most-itertools had a single-call solution: there's a reason why the project already has 1.2k ⭐ on GitHub!

Please give most-itertools a try and give this PR a 👍 if you find the package useful.

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/ptosi/master