Get difference from two lists in Python

Short answer, yes: list(set(l1) - set(l2)), though this will not keep order.

Long answer, no, since internally the CPU will always iterate. Though if you use set() that iteration will be done highly optimized and will be much faster then your list comprehension (not to mention that checking for membership value in list is much faster with sets then lists).

Leave a Comment