Skip to content

Instantly share code, notes, and snippets.

@psaitu
Last active September 12, 2015 07:13
Show Gist options
  • Select an option

  • Save psaitu/055b707bcb6e49f29b3d to your computer and use it in GitHub Desktop.

Select an option

Save psaitu/055b707bcb6e49f29b3d to your computer and use it in GitHub Desktop.
Representation of Trees
"""
>>> Tree = test_listing_2_8()
>>> t = Tree(Tree("a", Tree("b", Tree("c", Tree("d")))))
>>> t.kids.next.next.val
'c'
"""
class Tree:
def __init__(self, kids, next=None):
self.kids = self.val = kids
self.next = next
"""
>>> Tree = test_listing_2_7()
>>> t = Tree(Tree("a", "b"), Tree("c", "d"))
>>> t.right.left
'c'
"""
class Tree:
def __init__(self, left, right=None):
self.left = left
self.right = right
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment