def minmax_element(iterable, first=0, last=None, key=None):
    """
    Find and return the minimum and maximum element in an iterable range.

    Parameters
    ----------
    iterable: an iterable object with __get_item__
    first: first element to check
    last: one past last element to check. None will check until end of iterable
    key: function to be called on each list element prior to making comparisons

    Returns
    -------
    min_element, max_element: the resulting minmum and maximum elements
    """
    assert hasattr(iterable, '__getitem__')
    iterable = iterable if first == 0 and last is None else iterable[first:last]
    if key is None:
        return min(iterable), max(iterable)
    else:
        return min(iterable, key=key), max(iterable, key=key)