Joseph A. Joseph A. - 11 months ago 38
Python Question

Find the element "left" in a list

I have the list

list1 = ["Hello", "Goodbye", "Ohai"]

I have another list,
list2 = ["Hello", "Goodbye"]

I want to get the remaining items in
, in this case this would be

Answer Source
>>> list1 = ["Hello", "Goodbye", "Ohai"]
>>> list2 = ["Hello", "Goodbye"]
>>> set(list1) ^ set(list2)

If you are supposed to use lists only, you can iterate:

>>> [item for item in list1 if item not in list2]

But why do that when you have sets ;-)