Try to get the item at index position in iterable after iterate on
    iterable items.

    :param iterable: object which provides the method __getitem__ or __iter__.
    :param int index: item position to get.

def itemat(iterable, index):
    """Try to get the item at index position in iterable after iterate on
    iterable items.

    :param iterable: object which provides the method __getitem__ or __iter__.
    :param int index: item position to get.
    """

    result = None

    handleindex = True

    if isinstance(iterable, dict):
        handleindex = False

    else:
        try:
            result = iterable[index]
        except TypeError:
            handleindex = False

    if not handleindex:
        iterator = iter(iterable)

        if index < 0:  # ensure index is positive
            index += len(iterable)

        while index >= 0:
            try:
                value = next(iterator)

            except StopIteration:
                raise IndexError(
                    "{0} index {1} out of range".format(
                        iterable.__class__, index
                    )
                )

            else:
                if index == 0:
                    result = value
                    break
                index -= 1

    return result