Intersection of two nested lists in Python
I've a problem with the nested lists. I want to compute the lenght of the intersection of two nested lists with the python language. My lists are composed as follows: list1 = [[1,2], [2,3], [3,4]] list2 = [[1,2], [6,7], [4,5]] output_list = [[1,2]] How can i compute the intersection of the two lists? I think there are two reasonable approaches to solving this issue. If you don't have very many items in your top level lists, you can simply check if each sub-list in one of them is present in the other: intersection = [inner_list for inner in list1 if inner_list in list2] The in operator will