(iterable, default=0)
Safer variant of ``max()`` that returns a default value if the iterable
    is empty.

    Example:

        >>> safemax([-5, 6, 4])
        6
        >>> safemax([])
        0
        >>> safemax((), 2)
        2
Safer variant of ``max()`` that returns a default value if the iterable
    is empty.
Safer variant of max () that returns a default value if the iterable is empty .
def safemax(iterable, default=0):
    """Safer variant of ``max()`` that returns a default value if the iterable
    is empty.

    Example:

        >>> safemax([-5, 6, 4])
        6
        >>> safemax([])
        0
        >>> safemax((), 2)
        2
    """
    it = iter(iterable)
    try:
        first = next(it)
    except StopIteration:
        return default
    else:
        return max(chain([first], it))
def safemax ( iterable , default = 0 ) : it = iter ( iterable ) try : first = next ( it ) except StopIteration : return default else : return max ( chain ( [ first ] , it ) )