sorting a dictionary
Anton Vredegoor
anton at vredegoor.doge.nl
Tue Feb 4 06:35:42 EST 2003
On Tue, 4 Feb 2003 20:53:33 +1100, Andrew Bennetts
<andrew-pythonlist at puzzling.org> wrote:
>Sure you can... what's wrong with the solution I posted earlier:
>
> max([(x[1], x[0]) for x in d.items()])[1]
It creates many temporary objects. This one doesn't, and it can remain
at a higher level of ambiguity.
def get_highest(D):
def kmax(a,b):
if D.get(a)<D.get(b): return b
return a
return reduce(kmax,D)
Regards,
Anton.
More information about the Python-list
mailing list