[[x,f(x)] for x in list that maximizes f(x)] <--newbie help

Alex Martelli aleax at mail.comcast.net
Thu Dec 1 17:22:04 CET 2005


<bonono at gmail.com> wrote:
   ...
> thanks. I don't know what max can or cannot compare.

Just the same things that you can compare with, say, < .

I believe in 2.5 max and min will also accept a key= argument (like
sorted etc) to tweak what to compare, so max(thelist, key=f) should then
work (but in 2.4 you do need to more explicitly use some kind of
decorate-sort-undecorate idiom, as explained in previous posts).


Alex



More information about the Python-list mailing list