from itertools import islice
from typing import Iterable
from typing import Optional
from typing import Any


def nth(it: Iterable, n: int, default: Optional[Any] = None) -> Any:
    """
    Returns the nth item or a default value

    >>> nth(range(10), 5)
    5
    """
    return next(islice(it, n, None), default)