What is the cleanest (most "pythonic") way of printing every unique combination of three items in the following list?
strats = ["1","2","3","4"]
The solution needs to avoid duplicates:
1 and 1 and 1 No (not unique)
1 and 1 and 2 No (not unique)
1 and 1 and 3 No (not unique)
...
1 and 2 and 3 Yes
1 and 2 and 4 Yes
1 and 3 and 1 No (not unique)
1 and 3 and 2 No (occurred previously)
...
I am using numbers here just for clarity, the actual project involve text strings and there are 24 of them, but the same logic should apply.
Here is my first attempt:
strats = ["1","2","3","4"]
for a in strats:
for b in strats:
for c in strats:
if a != b and a != c and b!=c:
print(a+" and "+b+" and "+c)
The problem with the output is that it contains duplicates:
1 and 2 and 3 Fine
1 and 2 and 4 Fine
1 and 3 and 2 Duplicate
1 and 3 and 4 Fine
1 and 4 and 2 Duplicate
1 and 4 and 3 Duplicate
...