Nov-02-2019, 09:03 AM
from itertools import chain # converting your input data to a valid Python object: A = """ 1 0 1 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 1 0 0 0 0 0 1 0 0 0 1 0 0 1 """.strip() B = """ 0 1 0 0 1 0 0 1 1 1 0 0 0 0 0 1 1 1 1 0 0 0 0 1 1 0 1 0 1 0 0 1 """.strip() C = """ 1 0 1 0 1 0 0 1 1 0 1 1 1 0 0 1 1 0 1 0 0 0 0 1 1 1 0 0 1 0 0 1 """.strip() # nested list comprehension to create the matrix a = [[int(d) for d in a.split()] for a in A.splitlines()] b = [[int(d) for d in b.split()] for b in B.splitlines()] c = [[int(d) for d in c.split()] for c in C.splitlines()] # here are the functions def equality1(matrix1, matrix2): result = 0 for row1, row2 in zip(matrix1, matrix2): for col1, col2 in zip(row1, row2): if col1 == col2: result += 1 return result def equality2(matrix1, matrix2): result = 0 for m1, m2 in zip(chain.from_iterable(matrix1), chain.from_iterable(matrix2)): if m1 == m2: result += 1 return resultYou don't have to understand the upper part with the nested list comprehensions.
The function equality1 and equality2 should be descriptive enough, to understand it.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!