I'm trying to use itertools to create pairs of all possible combinations of three coin tosses, e.g., ['HHH', 'TTT'], ['HHH', 'THH'] .. [TTT', 'HTH'], .. , etc. I want to access the pairs as individual strings, and so far I have this; which doesn't seem very optimal?
from itertools import *
combs = []
combs.extend([list(x) for x in combinations(product('HT', repeat = 3), 2)])
for l in combs:
(one, two) = l
print ''.join(one), ''.join(two)
==edit==
Not sure whether it's ok to edit the original question - but here goes ..
What's the best way to remove duplicates, e.g., the pair (THT, THT) and reversed pairs - duplicates in reverse, e.g., (HHH, TTT) and (TTT, HHH)?
Thank you.
HHH HHH. Is that what you want? - DSM