I have a following list:
mylist = ['car', 'truck', 'ship']
Currently I am able to only get all the possible combinations of 2 strings using this:
from itertools import combinations
print(list(combinations(mylist,2)))
which gives me:
[('car', 'truck'), ('car', 'ship'), ('truck', 'ship')]
However, one combination is actually all the 3 strings. Thus I would like my outcome to be:
[('car', 'truck'), ('car', 'ship'), ('truck', 'ship'), ('car', 'truck', 'ship')]
('car')not in your result? what is it you actually need?list(set(combinations(mylist,2)).union(set(combinations(mylist, 3))]