I have a list of tuples each with two elements: [('1','11'),('2','22'),('3','33'),...n]
How would I find all the combinations of each tuple with only selecting one element of the tuple at a time?
The example results:
[[1,2,3],[11,2,3],[11,2,3],[11,22,33],[11,2,33],[11,22,3],[1,22,3],[1,22,33],[1,2,33]]`
itertools.combinations gives me all combinations but does not preserve selecting only one element from each tuple.
Thanks!
Use itertools.product:
In [88]: import itertools as it
In [89]: list(it.product(('1','11'),('2','22'),('3','33')))
Out[89]:
[('1', '2', '3'),
('1', '2', '33'),
('1', '22', '3'),
('1', '22', '33'),
('11', '2', '3'),
('11', '2', '33'),
('11', '22', '3'),
('11', '22', '33')]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With