Skip to content

Instantly share code, notes, and snippets.

@dotnwat
Created February 26, 2015 20:46
Show Gist options
  • Save dotnwat/534bdd24ecd26c13cfe9 to your computer and use it in GitHub Desktop.
Save dotnwat/534bdd24ecd26c13cfe9 to your computer and use it in GitHub Desktop.
def deepest_array(array, index):
sub_array = array[index[0]]
for component in index[1:-1]:
sub_array = sub_array[component]
return sub_array
def get_val(array, index):
return deepest_array(array, index)[index[-1]]
def set_val(array, index, value):
deepest_array(array, index)[index[-1]] = value
array = [
[1, 2, 3],
[4, 5, 6],
]
index = (1, 1)
print get_val(array, index)
# prints 5
set_val(array, index, 50)
print get_val(array, index)
# print 50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment