I'm doing a program that inputs a series of numbers, and takes 6 of them to make different combinations of lottery numbers. When I create the different combinations, I want to remove duplicates, so that each combination is only printed once. This is what I want to happen:
combo_list = [1 2 3 4 5 6 7]
And the output should be:
1 2 3 4 5 6
1 2 3 4 5 7
1 2 3 4 6 7
1 2 3 5 6 7
1 2 4 5 6 7
1 3 4 5 6 7
2 3 4 5 6 7
The code I'm using is:
final = []
for sublist in combo_list:
if sublist not in final:
final.append(sublist)
for item in final:
item = (sorted(item, key=int))
print (' '.join(str(n) for n in item))
However, I get an output with many duplicates when I use the code:
1 2 3 4 5 6
1 2 3 4 5 7
1 2 3 4 5 6
1 2 3 4 6 7
1 2 3 4 5 7
1 2 3 4 6 7
1 2 3 4 5 6
1 2 3 4 5 7
1 2 3 4 5 6
1 2 3 5 6 7
1 2 3 4 5 7
1 2 3 5 6 7
1 2 3 4 5 6
1 2 3 4 6 7
1 2 3 4 5 6
1 2 3 5 6 7
1 2 3 4 6 7
1 2 3 5 6 7
1 2 3 4 5 7
1 2 3 4 6 7
1 2 3 4 5 7
1 2 3 5 6 7
1 2 3 4 6 7
1 2 3 5 6 7
1 2 3 4 5 6
.
.
.
Any ideas on what I have to change for each of the combinations to only print once?