def min_cmp(L, cmp=None):
    """
    Returns the smallest item of a list (or iterable) with respect to
    a comparison function.

    INPUT:
        ``L``   -- an iterable
        ``cmp`` -- an optional comparison function.

    ``cmp(x, y)`` should return a negative value if `x < y`, `0` if
    `x == y`, and a positive value if `x > y`.

    OUTPUT: the smallest item of ``L`` with respect to ``cmp``.

    EXAMPLES::

        sage: from sage.misc.sage_itertools import min_cmp
        sage: L = [1,-1,3,-1,3,2]
        sage: min_cmp(L)
        -1
        sage: def mycmp(x,y): return y - x
        sage: min_cmp(L, mycmp)
        3

    The input can be any iterable::

        sage: min_cmp( (x^2 for x in L) )
        1
        sage: min_cmp( (x^2 for x in L), mycmp)
        9

    Computing the min of an empty iterable raises and error::

        sage: min_cmp([])
        Traceback (most recent call last):
        ...
        ValueError: min() arg is an empty sequence
        sage: min_cmp([], mycmp)
        Traceback (most recent call last):
        ...
        ValueError: min_cmp() arg is an empty sequence
    """
    if cmp is None:
        return min(L) # Resort to Python's standard min

    iterator = iter(L)
    try:
        m = next(iterator)
    except StopIteration:
        raise ValueError("min_cmp() arg is an empty sequence")
    for item in iterator:
        if cmp(item, m) < 0:
            m = item
    return m