Created
April 3, 2014 13:23
-
-
Save thomasballinger/9954255 to your computer and use it in GitHub Desktop.
simple recursive tree display
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
tree = [1, [2, [10, 3, 4], [11, 5, 6]], [12, 7,8]] | |
def display(t, indent=0): | |
if isinstance(t, list): | |
print ' '*indent, t[0] | |
display(t[1], indent+4) | |
display(t[2], indent+4) | |
else: | |
print ' '*indent, t | |
display(tree) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment