Question

Exercise 3 – Sets and Set Operations Imagine you have two grocery lists: Grocery Lists List...

Exercise 3 – Sets and Set Operations

Imagine you have two grocery lists:

Grocery Lists
List A List B
Soap Fish
Oranges Pork Loin
Bananas Paper Plates
Oatmeal Jelly
Fish Soap

Write python scripts that do the following:

  1. Prints names of products common to both lists.
  2. Prints names of products that are in at least one of the two lists.

Take a screenshot of your python code and the output.

Submit your well-labeled Word document that includes all specified elements.

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

l1=['Soap','Oranges','Bananas','Oatmeal','Fish']
l2=['Fish','Pork Loin','Paper Plates','Jelly','Soap']
#we can have set operations only on sets so convert lists into sets
#using set()
s1=set(l1) & set(l2)
#print it converting into list
print(list(s1))

For second question we need to do union operation on this lists

Add a comment
Know the answer?
Add Answer to:
Exercise 3 – Sets and Set Operations Imagine you have two grocery lists: Grocery Lists List...
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
ADVERTISEMENT