Browse Source

Itertools

pull/3/head
Jure Šorn 6 years ago
parent
commit
bc8c81e9f0
1 changed files with 10 additions and 10 deletions
  1. 20
      README.md

20
README.md

@ -752,25 +752,25 @@ from itertools import *
### Math ### Math
#### Combinations: #### Combinations
```python ```python
>>> combinations('abc', 2) >>> combinations('abc', 2)
[('a', 'b'), ('a', 'c'), ('b', 'c')] [('a', 'b'), ('a', 'c'), ('b', 'c')]
``` ```
#### Combinations with Replacement: #### Combinations with Replacement
```python ```python
>>> ombinations_with_replacement('abc', 2) >>> ombinations_with_replacement('abc', 2)
[('a', 'a'), ('a', 'b'), ('a', 'c'), ('b', 'b'), ('b', 'c'), ('c', 'c')] [('a', 'a'), ('a', 'b'), ('a', 'c'), ('b', 'b'), ('b', 'c'), ('c', 'c')]
``` ```
#### Permutations: #### Permutations
```python ```python
>>> permutations('abc', 2) >>> permutations('abc', 2)
[('a', 'b'), ('a', 'c'), ('b', 'a'), ('b', 'c'), ('c', 'a'), ('c', 'b')] [('a', 'b'), ('a', 'c'), ('b', 'a'), ('b', 'c'), ('c', 'a'), ('c', 'b')]
``` ```
#### Product: #### Product
```python ```python
>>> product('ab', [1, 2]) >>> product('ab', [1, 2])
[('a', 1), ('a', 2), ('b', 1), ('b', 2)] [('a', 1), ('a', 2), ('b', 1), ('b', 2)]
@ -778,33 +778,33 @@ from itertools import *
### Util ### Util
#### Chain: #### Chain
```python ```python
>>> chain([1, 2], range(3, 5)) >>> chain([1, 2], range(3, 5))
[1, 2, 3, 4] [1, 2, 3, 4]
``` ```
#### Compress: #### Compress
```python ```python
>>> compress('abc', [True, 0, 23]) >>> compress('abc', [True, 0, 23])
['a', 'c'] ['a', 'c']
``` ```
### Count: ### Count
```python ```python
>>> i = count(5, 2) >>> i = count(5, 2)
>>> next(i), next(i) >>> next(i), next(i)
(5, 7) (5, 7)
``` ```
#### Cycle: #### Cycle
```python ```python
>>> a = cycle('abc') >>> a = cycle('abc')
>>> [next(a) for _ in range(10)] >>> [next(a) for _ in range(10)]
['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a'] ['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a']
``` ```
#### Groupby: #### Groupby
```python ```python
>>> a = [{'id': 1, 'name': 'bob'}, >>> a = [{'id': 1, 'name': 'bob'},
{'id': 2, 'name': 'bob'}, {'id': 2, 'name': 'bob'},
@ -815,7 +815,7 @@ from itertools import *
'peter': [{'id': 3, 'name': 'peter'}]} 'peter': [{'id': 3, 'name': 'peter'}]}
``` ```
#### Islice: #### Islice
```python ```python
islice([1, 2, 3], 1, None) islice([1, 2, 3], 1, None)
[2, 3] [2, 3]

|||||||
100:0
Loading…
Cancel
Save