"""
A TreeList is a Python list with 3 elements
  --- element 0 is a value
  --- element 1 is either a TreeList or None
  --- element 2 is either a TreeList or None
"""

def preorder(tl: 'TreeList') -> list:
    """
    Return list of values in tl in preorder

    >>> preorder([5, [4, None, None], [3, [2, None, None], [1, None, None]]])
    [5, 4, 3, 2, 1]
    """
    
    return [] if tl is None else ([tl[0]] + preorder(tl[1]) + preorder(tl[2]))
#    if tl is None:
#        return []
#   else:
#      return [tl[0]] + preorder(tl[1]) + preorder(tl[2])
# return [] if (t1 is None) else ([t1[0]] + preorder ... etc)


def inorder(tl: 'TreeList') -> list:
    """
    Return a list of values of tl inorder

    >>> inorder([5, [4, None, None], [3, [2, None, None], [1, None, None]]])
    [4, 5, 2, 3, 1]
    """

    return ((inorder(tl[1]) if tl[1] else []) +
            [tl[0]] +
            (inorder(tl[2]) if tl[2] else []))

def postorder(tl: 'TreeList') -> list:
    """
    Return list of values in tl in postorder

    >>> postorder([5, [4, None, None], [3, [2, None, None], [1, None, None]]])
    [4, 2, 1, 3, 5]
    """

    return ((postorder(tl[1]) if tl[1] else []) +
            (postorder(tl[2]) if tl[2] else []) +
            [tl[0]])

if __name__ == '__main__':
    import doctest
    doctest.testmod()
