'Difference between two lists of lists in Python

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 1:[1]

You can iterate through one and check if it's in the other.

[numbers for numbers in a if numbers not in b]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sam