1# How to use it:
2# repeat(var, amount)
3
4# repeat() is basically like range() but it gives an extra arg for a var
5
6from itertools import repeat
7
8for x in repeat("Spam? Or Eggs?", 3):
9 print(x)
10> "Spam? Or Eggs?"
11> "Spam? Or Eggs?"
12> "Spam? Or Eggs?"
13
14
1#from itertools import product
2
3
4def product(*args, **kwds):
5 # product('ABCD', 'xy') --> Ax Ay Bx By Cx Cy Dx Dy
6 # product(range(2), repeat=3) --> 000 001 010 011 100 101 110 111
7 pools = map(tuple, args) * kwds.get('repeat', 1)
8 result = [[]]
9 for pool in pools:
10 result = [x+[y] for x in result for y in pool]
11 for prod in result:
12 yield tuple(prod)
13
1import itertools
2set = "abcde"
3for L in range(0, len(set) + 1)
4 for subset in itertools.combinations(letters, L): #all combinations in subset
5 list_comb.append(subset)
1from itertools import combinations_with_replacement
2
3s, k = input().split()
4
5for c in combinations_with_replacement(sorted(s), int(k)):
6 print("".join(c))
7