Last active
August 29, 2015 14:02
-
-
Save jesuscast/cf710d89fddba7599f32 to your computer and use it in GitHub Desktop.
Tree branches. Defines a tree as a tuple and then access the branches with 0 based index, the nesting is defined as another tuple.
This file contains hidden or 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
import math | |
def tree_ref(tree, index): | |
if(isinstance(index,(list,tuple)) and (len(index)>1)): | |
#print tree | |
#print index | |
#print "--1---" | |
newTree = tree[index[0]] | |
#print newTree | |
newIndex = tuple([index[k] for k in range(1,len(index))]) | |
#print newIndex | |
#print "-----2------" | |
return tree_ref(newTree, newIndex) | |
else: | |
if(isinstance(index,(list,tuple))): | |
return tree[index[0]] | |
else: | |
return tree[index] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment