You will need to convert the lists to a list of tuples, and then use the intersection. Note that the solution below may have the elements in a different order, and there will obviously not be duplicates, since I am using set.
In [1]: l1 = [[1, 2], [4], [5, 6, 2], [1, 2], [3], [4], [5,9]] In [2]: l2 = [[1, 2], [4], [5, 6, 2], [1, 2], [3], [4], [5,6], [1,2]] In [3]: [list(x) for x in set(tuple(x) for x in l1).intersection(set(tuple(x) for x in l2))] Out[3]: [[1, 2], [5, 6, 2], [3], [4]]
You can also save the intersection in a variable and get the final list, if order is needed, duplicates:
In [4]: intersection = set(tuple(x) for x in l1).intersection(set(tuple(x) for x in l2)) In [5]: [x for x in l1 if tuple(x) in intersection] Out[5]: [[1, 2], [4], [5, 6, 2], [1, 2], [3], [4]]
And the intersection, just in case you are interested.
In [6]: print intersection set([(1, 2), (5, 6, 2), (3,), (4,)])
This will work well for large lists, but if the lists are small, check out another @timegb solution (which will be very suboptimal for longer lists)