I want to count the number of common elements in two lists, where duplicates are treated separately (i.e. if 'a' is in one list once and the other list twice, it is only counted once, but if it is in both lists twice, it will be counted as 2).
x = [1, 2, 3, 4, 5, 5]
y = [1, 2, 5, 6, 7, 8]
The number of common elements here would be 3.
x = [1, 2, 3, 4, 5, 5]
y = [1, 2, 5, 6, 7, 8, 5]
The number of common elements here would be 4.
The closest command I found is
res = sum(i == j for i, j in zip(x, y))
It works except if there are two identical elements in both lists, it will only count them once.