How can I filter a list of lists based on another list/set in python. For a simple list this can be done as:
mylist = [1,2,3,4,5,3,5,2,3,2,7,5,3]
[x for x in mylist if x in {3,5}]
But how to do that for a list of lists most efficiently:
mylistoflists = [[], [5, 1, 6], [5, 1, 6, 2, 7], [5, 1, 6, 2, 7, 4, 8], [5, 1, 11, 10], [5, 1, 4, 11, 10, 12]]
myvalues = set([4,10])
The results should still be a list of lists like following:
[[], [], [], [4], [10], [4, 10]]
set([a,b,c])as the set literal{a,b,c}, mirroring the normal mathematical notation for sets.