def collapse_runs(seq):
    """Collapse runs of the same symbol in a sequence to a single symbol."""
    current = None
    out = []
    for x in seq:
        if x != current:
            out.append(x)
            current = x
    return out