Use tuples/lists as array indices (Python)
matrix, python
Solution
Here is one way:
matrx = [ [1,2,3], [4,5,6] ]
def LookupByTuple(tupl):
answer = matrx
for i in tupl:
answer = answer[i]
return answer
print LookupByTuple( (1,2) )
Problem
Assume I have an n-dimensional matrix in Python represented as lists of lists. I want to be able to use an n-tuple to index into the matrix. Is this possible? How? Thank you!