Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Brushed up solution in Clear category for Min and Max by maurice.makaay
from operator import gt, lt
def min(*args, key=None):
return _min_or_max(key, lt, args)
def max(*args, key=None):
return _min_or_max(key, gt, args)
def _min_or_max(key, compare, args):
result = None
for arg in args[0] if len(args) == 1 else args:
arg_key = arg if key is None else key(arg)
if result is None or compare(arg_key, result[1]):
result = (arg, arg_key)
return result[0]
Oct. 30, 2014