The prior solutions helped me a lot, but I also needed to change the value at the index of the tuple. For example:
access(l, (0,0,0)) = 7
.
The other solutions return a primitive value and so the nested list doesn't get updated.
I found that this approach, based on previous answers works (in case someone has the same need as me):
def set_it(obj, indexes, v):
a = obj
for i in indexes[:-1]:
a = a[i]
a[indexes[-1]] = v
Usage:
>>> l = [[[1, 2],
... [3, 4]],
... [[5, 6],
... [7, 8]]]
>>> set_it(l, (0, 0, 0), -1)
>>> l
[[[-1, 2], [3, 4]], [[5, 6], [7, 8]]]