Question

Python: How can I make a lists of three different lists? list1 = [('Skittles', '660000'), ("Hershey's...

Python: How can I make a lists of three different lists?

list1 = [('Skittles', '660000'), ("Hershey's Mini Chocolate Candy", '66000'), ("Reese's Peanut Butter Cups", '104940'), ('Sour Patch Kids', '105897'), ("Reese's Peanut Butter Cups", '91740'), ('Swedish Fish', '148731')]

list2 = [('Snickers', '543529'), ('Candy Corn', '40173'), ("M&M's", '86689'), ('Salt Water Taffy', '67389'), ("M&M's", '51374'), ('Hershey Kisses', '88136')]

list3 = [("Reese's Peanut Butter Cups", '194117'), ('Tootsie Pops', '34434'), ('Candy Corn', '41063'), ("M&M's", '24067'), ('Tootsie Pops', '36696'), ('Lemonheads', '38559')]

I want a list that will be [[list1, list2, list3] , [list1, list2, list3] ...]

ex: [[('Skittles', '660000'), ('Snickers', '543529'), ("Reese's Peanut Butter Cups", '194117')] , [("Hershey's Mini Chocolate Candy", '66000'), ('Candy Corn', '40173'), ('Tootsie Pops', '34434')], etc.]

0 0
Add a comment Improve this question Transcribed image text
Answer #1

If you have any doubts please comment below

Code:

list1 = [('Skittles', '660000'), ("Hershey's Mini Chocolate Candy", '66000'), ("Reese's Peanut Butter Cups", '104940'), ('Sour Patch Kids', '105897'), ("Reese's Peanut Butter Cups", '91740'), ('Swedish Fish', '148731')]

list2 = [('Snickers', '543529'), ('Candy Corn', '40173'), ("M&M's", '86689'), ('Salt Water Taffy', '67389'), ("M&M's", '51374'), ('Hershey Kisses', '88136')]

list3 = [("Reese's Peanut Butter Cups", '194117'), ('Tootsie Pops', '34434'), ('Candy Corn', '41063'), ("M&M's", '24067'), ('Tootsie Pops', '36696'), ('Lemonheads', '38559')]

# Taking result list

l=[]

# zip function is used to give list of tuple of tuples combining lists

for i in (zip(list1,list2,list3)):

  # Apending list of tuples to l list

  l.append(list(i))

print(l)

Add a comment
Know the answer?
Add Answer to:
Python: How can I make a lists of three different lists? list1 = [('Skittles', '660000'), ("Hershey's...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT