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 } } }

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

###

def countNodes(t):
    print(t)
    if t["left"] == None and t["right"] == None:
        return 1
    else:
        count = 0
        if t["left"] != None:
            count += countNodes(t["left"])
        if t["right"] != None:
            count += countNodes(t["right"])
        return count + 1

def countNodesTwo(t):
    print(t)
    if t == None:
        return 0
    else:
        count = 0
        count += countNodesTwo(t["left"])
        count += countNodesTwo(t["right"])
        return count + 1

###

def sumNodes(t):
    print(t)
    if t["left"] == None and t["right"] == None:
        print("->", t["contents"])
        return t["contents"]
    else:
        total = 0
        if t["left"] != None:
            total += sumNodes(t["left"])
        if t["right"] != None:
            total += sumNodes(t["right"])
        print("->", total + t["contents"])
        return total + t["contents"]

###

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