def expand(sequence):
    """
    expands a tree of sequences into a single, flat sequence, recursively.
    """
    expanse = []
    for point in sequence:
        if 'sequence' in point:
            expanse.extend(expand(point['sequence']))
        else:
            expanse.append(point)
    return sequence.__class__(expanse)