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 iv22
# migrated from python 2.7
def min(*args, **kwargs):
x = 0
for num in args:
#count in set
if isinstance(args[0], set):
set_list = list(args[0])
x = set_list[0]
# count in tuple
if isinstance(num, tuple):
x = num[0]
for n in num:
if n < x:
x = n
return x
# count in int
if isinstance(num, int):
x = num
for num in args:
if num < x:
x = num
return x
# count in list
if isinstance(num, list):
sev_list = ()
#list in list
if isinstance(num[0], list):
#sort with key
num.sort(**kwargs)
sev_list = num[0]
return sev_list
#list in tuple
if len(args) > 1:
x = args[0][0]
for n in args:
for num2 in n:
if num2 < x:
x = num2
sev_list = num
return sev_list
else:
num.sort()
return num[0]
return x
#count in generator
else:
generator = lambda x:[n for n in x]
b = generator(args[0])
for dig in b:
if dig < x:
x = dig
#count string
if isinstance(args[0], str):
x = args[0][0]
for letter in args[0]:
if ord(letter) < ord(x):
x = letter
return x
return x
########################################################
def max(*args, **kwargs):
key = kwargs.get("key", None)
dig = args, kwargs
x = 0
for n in args:
#count in set
if isinstance(n, set):
set_max = list(args[0])
x = set_max[0]
for l_set in set_max:
if ord(l_set) > ord(x):
x = l_set
#count with bool
if isinstance(n, bool):
bool_list = key #(lambda x: not x)
b = bool_list(args[0])
return b
# count in tuple
if isinstance(n, tuple):
for n in args:
if n > x:
x = n
return x
# count in int
if isinstance(n, int):
count = 0
if n > x:
x = n
print()
return x
# count in list
if isinstance(n, list):
x = 0
sev_list = ()
if len(args) > 1:
for n in args:
for num2 in n:
if num2 > x:
x = num2
sev_list = n
return sev_list
else:
for num2 in n:
if num2 > x:
x = num2
return x
# count with key int
if key == int:
x = 0
for n in dig[0]:
if int(n) > x:
x = n
# count in generator
else:
generator = lambda x:[n for n in x]
b = generator(args[0])
x = 0
for dig in b:
if dig > x:
x = dig
return x
Jan. 12, 2016