I am trying to create a program that will find and store the index of each element in the nested list.
So far, I have tried using nested for iterators to accomplish this.
Below is my code.
table = [[1, 1, 1], [2, 2, 2], [3, 3, 3]]
def coordinates(table):
target_cell_list = []
for row in table:
for column in row:
target_cell = (table.index(row), row.index(column))
target_cell_list.append(target_cell)
return target_cell_list
>>> table = [[1, 1, 1], [2, 2, 3], [2, 3, 3]]
>>> coordinates(table)
# current output
[(0, 0), (0, 0), (0, 0), (1, 0), (1, 0), (1, 2), (2, 0), (2, 1), (2, 1)]
# desired output
[(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2)]
I think the row indexes are outputting in a correct manner but the column indexes are doing something strange.
I have looked over the code several times but I cannot find out what's wrong with it.