I just started with python and very soon thought if indexing a nested list with a tuple is possible. Something like: elements[(1,1)]
One example where I wanted to do this was something similar to the code below, in which I store some matrix positions that I later need to get in a tuple called an index.
index = ( (0,0), (0,2), (2,0), (2,2) ) elements = [ [ 'a', 'b', 'c'], [ 'c', 'd', 'e'], [ 'f', 'g', 'h'] ] for i in index: print (elements [ i[0] ] [ i[1] ])
This seems to be a useful feature. Is there any way to do this? Or maybe a simple alternative?
source share