Browse Source

Permutations

pull/3/head
Jure Šorn 6 years ago
parent
commit
e68cf2fdb5
1 changed files with 9 additions and 4 deletions
  1. 13
      README.md

13
README.md

@ -875,16 +875,21 @@ from itertools import *
[('a', 'b'), ('a', 'c'), ('b', 'c')]
>>> combinations_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('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('ab', [1, 2])
[('a', 1), ('a', 2), ('b', 1), ('b', 2)]
[('a', 1), ('a', 2),
('b', 1), ('b', 2)]
>>> product([0, 1], repeat=3)
[(0, 0, 0), (0, 0, 1), (0, 1, 0), (0, 1, 1), (1, 0, 0), (1, 0, 1), (1, 1, 0), (1, 1, 1)]
[(0, 0, 0), (0, 0, 1), (0, 1, 0), (0, 1, 1),
(1, 0, 0), (1, 0, 1), (1, 1, 0), (1, 1, 1)]
```
### Infinite iterators

Loading…
Cancel
Save