Try to get the last iterable item by successive iteration on it.

    :param Iterable iterable: iterable to iterate on. Must provide the method
        __iter__.
    :param default: default value to get if input iterable is empty.
    :raises TypeError: if iterable is not an iterable value.

    :Example:

    >>> last('tests')
    's'
    >>> last('', default='test')
    'test'
    >>> last([])
    None

def last(iterable, default=None):
    """Try to get the last iterable item by successive iteration on it.

    :param Iterable iterable: iterable to iterate on. Must provide the method
        __iter__.
    :param default: default value to get if input iterable is empty.
    :raises TypeError: if iterable is not an iterable value.

    :Example:

    >>> last('tests')
    's'
    >>> last('', default='test')
    'test'
    >>> last([])
    None"""

    result = default

    iterator = iter(iterable)

    while True:
        try:
            result = next(iterator)

        except StopIteration:
            break

    return result