def last(iterable, default=_marker):
    """Return the last item of *iterable*, or *default* if *iterable* is
    empty.

        >>> last([0, 1, 2, 3])
        3
        >>> last([], 'some default')
        'some default'

    If *default* is not provided and there are no items in the iterable,
    raise ``ValueError``.
    """
    try:
        try:
            # Try to access the last item directly
            return iterable[-1]
        except (TypeError, AttributeError, KeyError):
            # If not slice-able, iterate entirely using length-1 deque
            return deque(iterable, maxlen=1)[0]
    except IndexError:  # If the iterable was empty
        if default is _marker:
            raise ValueError('last() was called on an empty iterable, and no '
                             'default value was provided.')
        return default
Return the last item of *iterable*, or *default* if *iterable* is
    empty.

        >>> last([0, 1, 2, 3])
        3
        >>> last([], 'some default')
        'some default'

    If *default* is not provided and there are no items in the iterable,
    raise ``ValueError``.