Created
February 26, 2015 20:46
-
-
Save dotnwat/534bdd24ecd26c13cfe9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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