Python Row, Column, Matrix Trouble
I'm writing a python program with with a given matrix = [['A', 'B', 'C'], ['D', 'E', 'F'], ['G', 'H', 'I']] I'm trying to write a code so that I can define
Solution 1:
You can always try this,
def getLoc(matrix, elem):
row , col = 0 , 0
for a in [j for i in matrix for j in i]:
if a == elem:
return row / len(matrix), col % len(matrix)
col += 1
row += 1
Post a Comment for "Python Row, Column, Matrix Trouble"