def getChildren(t):
    result = []
    leftT = t["left"]
    if leftT != None:
        result.append(leftT["contents"])
    rightT = t["right"]
    if rightT != None:
        result.append(rightT["contents"])
    return result


# Counting nodes using a base case of empty tree
def countNodes(t):
  if t == None:
    return 0
  else:
    # root node
    count = 1
    # left and right subtrees
    count += countNodes(t["left"])
    count += countNodes(t["right"])
    return count


# return sum of the node values
def sumNodes(t):
  if t == None:
    return 0
  else:
    # add contents of root node
    total = t["contents"]
	 # left and right subtrees
    total += sumNodes(t["left"])
    total += sumNodes(t["right"])
    return total


def listValues(t):
    if t == None:
        return []
    else:
        result =  [t["contents"]]
        result = result + listValues(t["left"])
        result = result + listValues(t["right"])
        return result

# this will get you left to right
def listValuesOther(t):
    if t == None:
        return []
    else:
        leftNodes = listValues(t["left"])
        rightNodes = listValues(t["right"])
        # changing order of what we return 
        return leftNodes + [t["contents"]] + rightNodes


# See slide 13 in lecture 7-2 for a visual representation of this tree
# Try drawing it yourself first! It's good practice :)
t = { "contents" : 6,
      "left"  : { "contents" : 3,
                  "left"  : { "contents" : 8,
                              "left"  : None,
                              "right" : None },
                  "right" : { "contents" : 7,
                              "left"  : None,
                              "right" : None } },
      "right" : { "contents" : 2,
                  "left"  : None,
                  "right" : { "contents" : 9,
                              "left"  : None,
                              "right" : None } } }

print("Children of root:", getChildren(t))
print("Children of node 3:", getChildren(t["left"]))
print("Children of node 2:", getChildren(t["right"]))

print("Count of nodes:", countNodes(t))
print("List of all nodes:", listValues(t))
# version where the nodes are left to right
print("List of all nodes left to right:", listValuesOther(t))