Possible Duplicate:
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 the coordinates for each value in the matrix. I have this to define the rows and column to get a coordinate:
def getLoc(key, elem):
row , col = 0 , 0
for a in [j for i in key for j in i]:
if a == elem:
return row / len(key), col % len(key)
col += 1
row += 1
That works to give me the coordinate for the letter but to work from the coordinate to get the letter I use:
def find_char(key, row, col):
for a in [j for i in key for j in i]:
if a == row , col = 0 , 0
return elem
This doesn’t give me a character. Why not?
I think find char should / could look like this