Are you looking for zip
z = [i == j for i,j in zip(x,y)]
But it is better to add int to get the desired result.
>>> z = [int(i == j) for i,j in zip(x,y)] >>> z [1, 0, 1, 0, 0]
else you will get a list, for example [True, False, True, False, False]
As ajcr is mentioned in comment , it is better to use itertools.izip instead of zip if the lists are very long. This is because an iterator is created instead of a list. This is mentioned in the documentation.
Like zip (), except that it returns an iterator instead of a list.
demo
>>> from itertools import izip >>> z = [int(i == j) for i,j in izip(x,y)] >>> z [1, 0, 1, 0, 0]
Bhargav rao
source share