im trying to compare between one list and 3 other lists with the same number of indexes. for example I have this list
[A, B, C]
and I have
You can do it like this:
from itertools import izip
def matches(input_lists, base_list):
for l in input_lists:
yield sum(1 for a, b in izip(l, base_list) if a==b)
and the result will be following:
>>> for i in matches([[1,2,3],[2,3,1],[0,2,0]], [1,2,4]):
i
2
0
1
which works as expected.
The izip() function is generator function, which is better solution than zip(). Also matches()
we defined is generator function, so there should be less problems when processing large lists.
Did it help? Is it clean enough?