N
Niels L Ellegaard
I just started learning python and I have been wondering. Is there a
short pythonic way to find the element, x, of a list, mylist, that
maximizes an expression f(x).
In other words I am looking for a short version of the following:
pair=[mylist[0],f(mylist[0])]
for x in mylist[1:]:
if f(x) > pair[1]:
pair=[x,f(x)]
short pythonic way to find the element, x, of a list, mylist, that
maximizes an expression f(x).
In other words I am looking for a short version of the following:
pair=[mylist[0],f(mylist[0])]
for x in mylist[1:]:
if f(x) > pair[1]:
pair=[x,f(x)]