from typing import Iterable
import itertools


def sliding_window(iterable: Iterable, n: int = 2) -> Iterable:
    """Create a sliding window on an iterable.

    Args:
        iterable: An iterable to create a sliding window over.
        n: The size of the sliding window. Defaults to 2.

    Returns:
        An iterable where each element is a window of size n on the
        original iterable.

    Example:
        >>> list(sliding_window(range(5), 3))
        [(0, 1, 2), (1, 2, 3), (2, 3, 4)]
    """
    iterables = itertools.tee(iterable, n)
    for iterable, num_skipped in zip(iterables, itertools.count()):
        for _ in range(num_skipped):
            next(iterable, None)
    return zip(*iterables)