list - What is the best way to use a two value pair as a key in python? -


i attempting use matrix in pythons. have heard things list of lists, wasn't sure easiest way manipulate these values be. want there value stored @ coordinates (x,y) on grid, accessed having both x , y. like:

x = 3 y = 4 matrix[3][4] = value 

you can store tuple of (x, y) key in dictionary:

matrix = {(1, 1): value1, (1, 2): value2, ...} 

you can retrieve value associated coordinate follows:

value = matrix[(1, 2)] 

Comments