aphid308
4/25/2017 - 4:41 PM

Return Difference Between Lists

Python list comprehension to return a list of items from list A that are not in list B.

a = ["Peter", "Lois", "Stewey", "Quagmire", "Brian", "Chris", "Meg"]
b = ["Lois", "Brian", "Meg"]

return [x for x in set(a).difference(b)]

"""
returns
["Peter", "Stewey", "Quagmire", "Chris"]
"""