Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Single generic function with no comments solution in Clear category for Min and Max by virzen
def lt(val1, val2):
return val1 < val2
def gt(val1, val2):
return val1 > val2
def find(cmp, *args, **kwargs):
if len(args) < 1:
return None
key = kwargs.get("key", lambda x: x)
arguments = list(args[0]) if len(args) == 1 else args
result = arguments[0]
for val in arguments:
if cmp(key(val), key(result)):
result = val
return result
min = lambda *args, **kwargs: find(lt, *args, **kwargs)
max = lambda *args, **kwargs: find(gt, *args, **kwargs)
Dec. 13, 2016