Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
My "min" and "max" built-in functions solution in Clear category for Min and Max by Phil15
def min(*args, **kwargs):
key = kwargs.get("key", lambda x:x)
mini = None
if len(args)==1:
args = args[0]
for arg in args:
if mini==None or key(arg)maxi[1]:
maxi = arg, key(arg)
return maxi[0]
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert min(3, 2) == 2, "Simple case min"
assert min("hello") == "e", "From string"
assert min(-5, -6, 2, -2, 3, 6) == -6
assert min(-5, -6, 2, -2, 3, 6, key=abs) == 2
assert min([[1, 2], [3, 4], [9, 0]], key=lambda x: x[1]) == [9, 0], "lambda key"
assert max(3, 2) == 3, "Simple case max"
assert max([1, 2, 0, 3, 4]) == 4, "From a list"
assert max(2.2, 5.6, 5.9, key=int) == 5.6, "Two maximal items"
print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")
March 6, 2018