Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Min and Max by Gray_Wind
def minmax(is_min, args, kwargs):
def _minmax(a, b, is_min):
if is_min:
return a < b
else:
return a > b
if len(args) == 1:
args = iter(args[0])
else:
args = iter(args)
key = kwargs.get("key", lambda x: x)
rv = next(args)
try:
while True:
arg = next(args)
if _minmax(key(rv), key(arg), is_min):
rv = arg
except StopIteration:
pass
return rv
def min(*args, **kwargs):
return minmax(False, args, kwargs)
def max(*args, **kwargs):
return minmax(True, args, kwargs)
June 18, 2015