Yields all permutations with replacement: list(product("cat", repeat=2)) => [("c", "c"), ("c", "a"), ("c", "t"), ("a", "c"), ("a", "a"), ("a", "t"), ("t", "c"), ("t", "a"), ("t", "t")]
(*args, **kwargs)
| 122 | return product(iterable, repeat=n) |
| 123 | |
| 124 | def product(*args, **kwargs): |
| 125 | """ Yields all permutations with replacement: |
| 126 | list(product("cat", repeat=2)) => |
| 127 | [("c", "c"), |
| 128 | ("c", "a"), |
| 129 | ("c", "t"), |
| 130 | ("a", "c"), |
| 131 | ("a", "a"), |
| 132 | ("a", "t"), |
| 133 | ("t", "c"), |
| 134 | ("t", "a"), |
| 135 | ("t", "t")] |
| 136 | """ |
| 137 | p = [[]] |
| 138 | for iterable in map(tuple, args) * kwargs.get("repeat", 1): |
| 139 | p = [x + [y] for x in p for y in iterable] |
| 140 | for p in p: |
| 141 | yield tuple(p) |
| 142 | |
| 143 | try: from itertools import product |
| 144 | except: |
no test coverage detected
searching dependent graphs…