def get_pairs(some_list, limit):
min = 2
pair_dict = collections.defaultdict(list)
for x in range(min, limit+1):
temp_list = list(itertools.combinations(some_list, x))
pair_dict[x].append(temp_list)
return pair_dict
z = get_pairs([1, 2, 3, 4], 4)
for key, value in z.items():
print("Key: {}, Value: {}".format(key, value))
Output:
Key: 2, Value: [[(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)]]
Key: 3, Value: [[(1, 2, 3), (1, 2, 4), (1, 3, 4), (2, 3, 4)]]
Key: 4, Value: [[(1, 2, 3, 4)]]
But What I want is something like below
Expected output:
Key: 2, Value: [[(1, 2), (3, 4)]]
Key: 3, Value:[[(1, 2, 3)]]
Key: 4, Value: [[(1, 2, 3, 4)]]