is itertools built in code example
Example 1: itertools
from itertools import combinations
from itertools import permutations
Example 2: python product
def product(*args, **kwds):
pools = map(tuple, args) * kwds.get('repeat', 1)
result = [[]]
for pool in pools:
result = [x+[y] for x in result for y in pool]
for prod in result:
yield tuple(prod)
Example 3: python itertools repeat()
from itertools import repeat
for x in repeat("Spam? Or Eggs?", 3):
print(x)
> "Spam? Or Eggs?"
> "Spam? Or Eggs?"
> "Spam? Or Eggs?"