>>> def myMax(iterable,/,*vars,key=None,default=None):
if vars:
if default is not None:
raise TypeError("Cannot specify a default for max() with multiple positional arguments")
greatest=iterable
flag=key(greatest)
else:
iterator=iter(iterable)
if default is None:
try:
greatest=next(iterator)
except StopIteration:
raise ValueError("max() arg is an empty sequence")
else:
greatest=default
if key is None:
for var in vars:
if var>greatest:
greatest=var
return greatest
else:
flag=key(greatest)
for var in vars:
if (k:=key(var))>flag:
flag=k
greatest=var
return greatest
>>> max(1, 2, 3)
3
>>> myMax(1, 2, 3)
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
myMax(1, 2, 3)
File "<pyshell#6>", line 7, in myMax
flag=key(greatest)
TypeError: 'NoneType' object is not callable
|