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 vinc
def cmp(oper, *args, **kwargs):
func = kwargs.get("key", lambda x: x)
args = iter(args if len(args) > 1 else args[0])
best = next(args)
best_value = func(best)
for arg in args:
arg_value = func(arg)
if oper(arg_value, best_value):
best, best_value = arg, arg_value
return best
lt = lambda x, y: x < y
gt = lambda x, y: x > y
min = lambda *args, **kwargs: cmp(lt, *args, **kwargs)
max = lambda *args, **kwargs: cmp(gt, *args, **kwargs)
Oct. 2, 2014
Comments: