I have the following code
a = [1, 2, 3, 4, 5, 6]
b = [1, 3, 3, 4, 5, 7]
counter = 0
for x,y in tuple(zip(a, b)):
if x==y:
counter += 1
How do I write that in one line? I tried this counter+= 1 if ((x==y) for (x, y) in tuple(zip(a, b))) else None but it adds 1 to the counter and that's all.
Aucun commentaire:
Enregistrer un commentaire