From 73e980a8b0fe5872c8c0d688562bd1d0c2383b08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 23 Nov 2018 19:58:14 +0100 Subject: [PATCH] Itertools --- README.md | 45 ++++++++++++++++++--------------------------- 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 3382b46..15b08c9 100644 --- a/README.md +++ b/README.md @@ -750,7 +750,7 @@ Itertools from itertools import * ``` -### Math +### Combinatoric Iterators ```python >>> combinations('abc', 2) @@ -766,36 +766,33 @@ from itertools import * [('a', 1), ('a', 2), ('b', 1), ('b', 2)] ``` -### Util +### Infinite iterators -#### Chain -```python ->>> chain([1, 2], range(3, 5)) -[1, 2, 3, 4] -``` - -#### Compress -```python ->>> compress('abc', [True, 0, 23]) -['a', 'c'] -``` - -#### Count ```python >>> i = count(5, 2) ->>> next(i), next(i) -(5, 7) -``` +>>> next(i), next(i), next(i) +(5, 7, 9) -#### Cycle -```python >>> a = cycle('abc') >>> [next(a) for _ in range(10)] ['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a'] + +>>> repeat(10, 3) +[10, 10, 10] ``` -#### Groupby +### Iterators + ```python +>>> chain([1, 2], range(3, 5)) +[1, 2, 3, 4] + +>>> compress('abc', [True, 0, 1]) +['a', 'c'] + +islice([1, 2, 3], 1, None) # islice(, from_inclusive, to_exclusive) +[2, 3] + >>> a = [{'id': 1, 'name': 'bob'}, {'id': 2, 'name': 'bob'}, {'id': 3, 'name': 'peter'}] @@ -805,12 +802,6 @@ from itertools import * 'peter': [{'id': 3, 'name': 'peter'}]} ``` -#### Islice -```python -islice([1, 2, 3], 1, None) -[2, 3] -``` - ### Ifilter, imap and izip #### Filter, map and zip functions that return generators instead of iterators.