def sliding_window(seq, lookahead):
    """
    Create a sliding window with the specified number of lookahead characters.
    """
    it = itertools.chain(iter(seq), ' ' * lookahead)  # Padded iterator
    window_size = lookahead + 1
    result = tuple(itertools.islice(it, window_size))
    if len(result) == window_size:
        yield result
    for elem in it:
        result = result[1:] + (elem,)
        yield result
Create a sliding window with the specified number of lookahead characters.