[[x,f(x)] for x in list that maximizes f(x)] <--newbie help
Niels L Ellegaard
niels.ellegaard at gmail.com
Thu Dec 1 08:45:54 EST 2005
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)]
More information about the Python-list
mailing list