Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Second solution in Speedy category for Min and Max by Renelvon
def min(*args, key=lambda x: x):
it = iter(args if len(args) > 1 else args[0])
mmin = it.__next__()
mminkey = key(mmin)
for m, mkey in ((x, key(x)) for x in it):
if mkey < mminkey:
mmin, mminkey = m, mkey
return mmin
def max(*args, key=lambda x: x):
it = iter(args if len(args) > 1 else args[0])
mmax = it.__next__()
mmaxkey = key(mmax)
for m, mkey in ((x, key(x)) for x in it):
if mkey > mmaxkey:
mmax, mmaxkey = m, mkey
return mmax
May 14, 2014
Comments: