0

Let's say that i have:

usa = ["kebab","pizza", "hamburger"]
uk = ["kebab", "hamburger"]

How do i check if uk has all the meals that usa has?

I have tried this:

for i in usa: 
if i not in str(uk):
    print("UK doesn't serve %s" % i)

This works but only returns on missing item on uk's list. I need to know exactly what is missing. and this meal list might contain around 1000 or more records

YakuzaNY
  • 69
  • 1
  • 8

2 Answers2

2

Use set:

usa = ["kebab","pizza", "hamburger"]
uk = ["kebab", "hamburger"]

s1 = set(usa)
s2 = set(uk)

s1.issuperset(s2) # True
s2.issubset(s1)   # False

And find the intersection:

s1.intersection(s2) # {'hamburger', 'kebab'}
knh190
  • 2,744
  • 1
  • 16
  • 30
1

You can use the following comprehension way using all

usa = ["kebab","pizza", "hamburger"]
uk = ["kebab", "hamburger"]

print (all(i in usa for i in uk))
# True
Sheldore
  • 37,862
  • 7
  • 57
  • 71