<jupyter_start><jupyter_text>Tree and Binary Tree<jupyter_code>from pprint import pprint<jupyter_output><empty_output><jupyter_text>List of Lists Representation<jupyter_code>myTree = ['a',   #root
      ['b',  #left subtree
       ['d', [], []],
       ['e', [], []] ],
      ['c',  #right subtree
       ['f', [], []],
       [] ]
     ]
pprint(myTree)
pprint(myTree[0])  # root
pprint(myTree[1])  # left tree
pprint(myTree[2])  # right tree
def binaryTree(r):
    return [r, [], []]
def insertLeft(root,newBranch):
    t = root.pop(1)
    if len(t) > 1:
        root.insert(1,[newBranch,t,[]])
    else:
        root.insert(1,[newBranch, [], []])
    return root
def insertRight(root,newBranch):
    t = root.pop(2)
    if len(t) > 1:
        root.insert(2,[newBranch,[],t])
    else:
        root.insert(2,[newBranch,[],[]])
    return root
def getRootVal(root):
    return root[0]

def setRootVal(root,newVal):
    root[0] = newVal

def getLeftChild(root):
    return root[1]

def getRightChild(root):
    return root[2]
def buildTree():
    root = binaryTree('a')
    insertLeft(root, 'b')
    insertRight(root, 'c')
    insertRight(getLeftChild(root), 'd')
    insertLeft(getRightChild(root), 'e')
    insertRight(getRightChild(root), 'f')
    
    return root
root = buildTree()
print(root)<jupyter_output>['a', ['b', [], ['d', [], []]], ['c', ['e', [], []], ['f', [], []]]]
{'fraction_non_alphanumeric': 0.2056480811006517, 'fraction_numerical': 0.010861694424330196, 'mean_word_length': 3.487012987012987, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '136661', 'license': 'MIT', 'n_tokens_mistral': 531, 'n_tokens_neox': 528, 'n_words': 98, 'path': 'dsa/Tree/Tree and Binary Tree.ipynb', 'repo_name': 'callmexss/learn-python', 'size': '1381'}