Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
10th solution in Clear category for Min and Max by arek.kowalski107
import types
#POLITECH
def parse_args(args, key):
ret = [key(i) for i in args]
return ret
def nomalise_args(*args):
new_args = [None]
while len(new_args) == 1:
new_args = list(args[0])
if isinstance(new_args, types.GeneratorType):
new_args = list(new_args)
if new_args == args[0] or type(new_args[0]) in [int, float]:
break
args = new_args
return new_args
def find_value(args, biggest=True):
index = 0
value = args[0]
for i, v in enumerate(args):
if (biggest and v > value) or (not biggest and v < value):
index = i
value = v
return index
def min(*args, **kwargs):
key = kwargs.get("key", None)
nomalised_args = nomalise_args(args)
if key:
parsed_args = parse_args(nomalised_args, key)
else:
parsed_args = nomalised_args
return nomalised_args[find_value(parsed_args, False)]
def max(*args, **kwargs):
key = kwargs.get("key", None)
nomalised_args = nomalise_args(args)
if key:
parsed_args = parse_args(nomalised_args, key)
else:
parsed_args = nomalised_args
return nomalised_args[find_value(parsed_args)]
Dec. 10, 2016