def map_labels(tree, fn):
    
    """Returns a tree in which every node's label is mapped by fn"""

    if isinstance(tree, list):
        return [fn(tree[0])]+[map_labels(child,fn) for child in tree[1:]]
    else:
        return tree