def flatten(tree):

    """Flattens a tree to a list.

    Example: ["one", ["two", ["three", ["four"]]]]
    becomes: ["one", "two", "three", "four"]

    """

    i = 0
    while i < len(tree):
        while isinstance(tree[i], (list, tuple)):
            if not tree[i]:
                tree.pop(i)
                if not len(tree): break
            else:
                tree[i:i+1] = list(tree[i])
        i += 1
    return tree