Answer the question
In order to leave comments, you need to log in
Get combination of two tuples?
I'm looking for a one-liner to get combinations of elements of two tuples.
tuple_one = ('one', 'two', .... 'thousand') # name
tuple_two = ('blue', 'black', 'yellow', .......) # color
[('one', 'blue'), ('one', 'black',) ('one', 'yelow') ....... ('two', 'blue'), ('two', 'black',) ('two', 'yelow')]
Answer the question
In order to leave comments, you need to log in
from itertools import product
tuple_one = ('one', 'two', 'thousand') # name
tuple_two = ('blue', 'black', 'yellow') # color
print(list(product(tuple_one, tuple_two)))
[('one', 'blue'), ('one', 'black'), ('one', 'yellow'), ('two', 'blue'), ('two', 'black'), ('two', 'yellow'), ('thousand', 'blue'), ('thousand', 'black'), ('thousand', 'yellow')]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question