I am using the following script to compare the elements in two separate lists in Python3. If an element matches e.g. element [0]
from list one matches element [0]
from list two then the variable c
is incremented by one. If the element does not match but the value is in the list then a different variable d
is incremented.
I have put the code together but it is rather long and wanted to know if it could be condensed in some way.
a = [1,2,3,4]
b = [2,1,3,4]
c = 0
d = 0
if a[0] == b[0]:
c += 1
elif a[0] == b[1] or a[0] == b[2] or a[0] == b[3]:
d += 1
if a[1] == b[1]:
c += 1
elif a[1] == b[0] or a[1] == b[2] or a[1] == b[3]:
d += 1
if a[2] == b[2]:
c += 1
elif a[2] == b[0] or a[2] == b[1] or a[2] == b[3]:
d += 1
if a[3] == b[3]:
c += 1
elif a[3] == b[0] or a[3] == b[1] or a[3] == b[2]:
d += 1