find minimum associated values
aisaac at american.edu
Fri Jan 25 23:28:51 CET 2008
Paul Rubin wrote:
> How about something like:
> kv_sorted = sorted(kv, key=lambda x: (id(x), x))
You mean like this?
#sort by id and then value
kv_sorted = sorted(kv, key=lambda x: (id(x),x))
#groupby: first element in each group is object and its min value
d =dict( g.next() for k,g in groupby( kv_sorted, key=lambda x: x ) )
Yes, that appears to be fastest and is
pretty easy to read.
More information about the Python-list