EDIT: Looking for the number of matches not the matches themselves. Cannot solve with sets or [x for x in list1 if x in list2] type manner. list1.count(x) if x in list2 works though.
Let's say you have two lists, list1 and list2, and want to find the number of times a value from list1 matches a value from list2.
I used the following code to perform this task successfully -
sum([x==y for x in list1 for y in list2])
The problem is this code cannot handle larger lists efficiently. Is there a faster, more efficient, dare I say more pythonic way to solve this problem than the "double for" loop?