Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)

I have the two lists as:

a = ['apple', 'mango', 'pear']

b = ['ripe','raw','rotten']

How can I get the below result, list of tuples as:

[(('apple', 'mango', 'pear'), 'ripe'), (('apple', 'mango', 'pear'), 'raw'), (('apple', 'mango', 'pear'), 'rotten')]

1 Answer

0 votes
by (36.8k points)

The list(itertools.product(a,b)) will use element in A.To make full list as the element, you could use nested list,like this:

list(itertools.product([tuple(a)], b)

Result:

[(('apple', 'mango', 'pear'), 'ripe'), (('apple', 'mango', 'pear'), 'raw'), (('apple', 'mango', 'pear'), 'rotten')]

 If you want to know more about the Data Science then do check out the following Data Science which will help you in understanding Data Science from scratch

Browse Categories

...