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:
>>>fromitertoolsimportrepeat>>>(10for_inrange(3))# Instead of this ...>>>repeat(10,3)# ... use that!
and more-itertools is based on the same idea and provides many more building blocks:
>>>frommore_itertoolsimportilen>>>sum(1for_initer)# 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):
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.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.
## 📋 Pull Request Information
**Original PR:** https://github.com/vinta/awesome-python/pull/1470
**Author:** [@ptosi](https://github.com/ptosi)
**Created:** 2/7/2020
**Status:** ✅ Merged
**Merged:** 4/7/2020
**Merged by:** [@vinta](https://github.com/vinta)
**Base:** `master` ← **Head:** `master`
---
### 📝 Commits (1)
- [`d6b358e`](https://github.com/vinta/awesome-python/commit/d6b358ea97b80c6e8fce9873e36faef1af0d85cc) add more-itertools
### 📊 Changes
**1 file changed** (+1 additions, -0 deletions)
<details>
<summary>View changed files</summary>
📝 `README.md` (+1 -0)
</details>
### 📄 Description
## 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`](https://github.com/erikrose/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:
```Python
>>> 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:
```Python
>>> 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)`](https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.all_equal)
- [`last(iterable[, default])`](https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.last)
- [`nth(iterable, n, default=None)`](https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.nth)
- [`consume(iterator, n=None)`](https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.consume)
- [`distribute(n, iterable)`](https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.distribute)
- [`roundrobin(*iterables)`](https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.roundrobin)
- [`windowed(seq, n, fillvalue=None, step=1)`](https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.windowed)
- [`substrings(iterable)`](https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.substrings)
- [`powerset(iterable)`](https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.powerset)
- [`random_permutation(iterable, r=None)`](https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.random_permutation)
- [`with_iter(context_manager)`](https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.with_iter)
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 :star: on GitHub!
Please give `most-itertools` a try and give this PR a :+1: if you find the package useful.
---
<sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
📋 Pull Request Information
Original PR: https://github.com/vinta/awesome-python/pull/1470
Author: @ptosi
Created: 2/7/2020
Status: ✅ Merged
Merged: 4/7/2020
Merged by: @vinta
Base:
master← Head:master📝 Commits (1)
d6b358eadd more-itertools📊 Changes
1 file changed (+1 additions, -0 deletions)
View changed files
📝
README.md(+1 -0)📄 Description
What is this Python project?
From the README of the project:
What's the difference between this Python project and similar ones?
more-itertoolsprovides most re-usable functions one would want when working with iterables. By relying on this lightweight package, similarly to whatitertoolsprovide, 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
itertoolswhen appropriate:and
more-itertoolsis based on the same idea and provides many more building blocks: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-itertoolshad a single-call solution: there's a reason why the project already has 1.2k ⭐ on GitHub!Please give
most-itertoolsa try and give this PR a 👍 if you find the package useful.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.