-
Notifications
You must be signed in to change notification settings - Fork 0
/
combinations.py
39 lines (32 loc) · 1.09 KB
/
combinations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
def generate_two_different(choices: [any]):
for i, c1 in enumerate(choices):
for j, c2 in enumerate(choices):
if j > i:
yield c1, c2
def generate_all_combinations(choices: [any]):
for i, c1 in enumerate(choices):
combination = [c1]
yield combination.copy()
tmp_combination = combination.copy()
for combo in generate_all_combinations(choices[i+1:]):
combination.extend(list(combo))
yield combination.copy()
combination = tmp_combination.copy()
def generate_combos_one_of_each(**kwargs) -> dict:
# print(kwargs)
keys = set(kwargs.keys())
if len(keys) > 0:
key = keys.pop()
values = kwargs.pop(key)
assert type(values) is list
d = {}
for v in values:
d[key] = v
# print(d)
if len(kwargs.keys()) > 0:
for d2 in generate_combos_one_of_each(**kwargs):
# print(d2)
d.update(d2)
yield d.copy()
else:
yield d.copy()