I would like to give some feedback about ...
From: https://py.checkio.org/mission/min-max/solve/
HTTP_USER_AGENT:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36
i think my code is okay and in my visualstudio do well my code. but it is not working my code in this web.
error is
TypeError: 'generator' object is not subscriptable, min, 8, , 9
"min(abs(i) for i in range(-10, 10))"
my code is
def min(*args, **kwargs):
key = kwargs.get("key", None)
if key==None:
if len(args)==1:
b=args[0]
else:
b=args
mi=b[0]
for i in range(len(b)):
if mi>b[i]:
mi=b[i]
else:
pass
else:
if len(args)==1:
b=args[0]
else:
b=args
mi=b[0]
for i in range(len(b)):
if key(mi)>key(b[i]):
mi=b[i]
else:
pass
return mi
def max(*args, **kwargs):
key = kwargs.get("key", None)
if key==None:
if len(args)==1:
b=args[0]
else:
b=args
mi=b[0]
for i in range(len(b)):
if mi<b[i]:
mi=b[i]
else:
pass
else:
if len(args)==1:
b=args[0]
else:
b=args
mi=b[0]
for i in range(len(b)):
if key(mi)<key(b[i]):
mi=b[i]
else:
pass
return mi
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert max(3, 2) == 3, "Simple case max"
assert min(3, 2) == 2, "Simple case min"
assert max([1, 2, 0, 3, 4]) == 4, "From a list"
assert min("hello") == "e", "From string"
assert max(2.2, 5.6, 5.9, key=int) == 5.6, "Two maximal items"
assert min([[1, 2], [3, 4], [9, 0]], key=lambda x: x[1]) == [9, 0], "lambda key"
Created at: 2017/02/11 10:03; Updated at: 2017/02/11 21:25
The question is resolved.