I have two lists of lists:
a = [[1,2,3],[4,5,6],[7,8,9]]
b = [[1,2,3],[9,9,9]]
I would like to get a set difference between them – expected outcome:
c = a - b = [[4,5,6],[7,8,9]].
I tried set() and set.difference() but it seems not to be able to compare lists.
>Solution :
Just use list comprehensions like so:
a = [[1,2,3],[4,5,6],[7,8,9]]
b = [[1,2,3],[9,9,9]]
c = [d for d in a if d not in b]
print(c)
Output:
[[4, 5, 6], [7, 8, 9]]