find minimum associated values

Paul Rubin http
Fri Jan 25 20:56:11 CET 2008


Alan Isaac <aisaac at american.edu> writes:
> print "method 2: groupby"
> t=time.clock()
> d = dict()
> kv_sorted = sorted(kv, key=lambda x: id(x[0]))

How about something like:

  kv_sorted = sorted(kv, key=lambda x: (id(x[0]), x[1]))

Now do your groupby and the first element of each group is the minimum
for that group.



More information about the Python-list mailing list