I must create a function, that takes a matrix as an argument and uses list comprehension to divide each element of the list by 2 if it is an even number. So if the argument passed to the function was m = [[5, 4], [2, 3], [6, 7]] The function would return the matrix m2 = [[5, 2], [1, 3], [3, 7]]
I have tried the following:
m = [[5, 4], [2, 3], [6, 7]]
result = [num / 2 for num in m if num % 2 == 0]
print (result)
But I receive this error:
line 2, in <listcomp>
result = [num / 2 for num in m if num % 2 == 0]
TypeError: unsupported operand type(s) for %: 'list' and 'int'