sorting a dictionary
Nick Vargish
nav at adams.patriot.net
Wed Feb 5 07:48:01 EST 2003
John La Rooy <nospampls.jlr at doctor.com> writes:
> It is O(N)
Oh. Cool. I thought the "max()" call would count against me,
somehow... Is it too late for this old dog to learn O(n) metrics? :^)
> def key_of_highest(d):
> mv = max(d.values())
> return [k for k in d if d[k]==mv][0]
It's terser, but lacks the potential early escape that the explicit
for/test/break approach gives you.
Nick
--
# sigmask.py || version 0.2 || 2003-01-07 || Feed this to your Python.
print reduce(lambda x,y:x+chr(ord(y)-1),'Ojdl!Wbshjti!=obwAqbusjpu/ofu?','')
More information about the Python-list
mailing list