Skip to content

Instantly share code, notes, and snippets.

@JIElite
Created February 3, 2022 00:39
Show Gist options
  • Select an option

  • Save JIElite/f78634cc3f446e992779ee5d2c78b7e9 to your computer and use it in GitHub Desktop.

Select an option

Save JIElite/f78634cc3f446e992779ee5d2c78b7e9 to your computer and use it in GitHub Desktop.
import pprint
import types
class Node(types.SimpleNamespace):
def __init__(self, val=None, right=None, left=None):
self.val = val
self.right = right
self.left = left
n1 = Node(1)
n1.right = Node(2)
n1.left = Node(3)
n1.right.right = Node(4)
n2 = Node(7)
n2.right = Node(8)
n2.a = '@@'
n1.right.left = [Node(5), Node(6), {'test': n2}, [{'test2': Node(11)}]]
pprint.pprint(n1)
# Node(val=1,
# right=Node(val=2,
# right=Node(val=4, right=None, left=None),
# left=[Node(val=5, right=None, left=None),
# Node(val=6, right=None, left=None),
# {'test': Node(val=7,
# right=Node(val=8, right=None, left=None),
# left=None,
# a='@@')},
# [{'test2': Node(val=11, right=None, left=None)}]]),
# left=Node(val=3, right=None, left=None))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment