find minimum associated values

Alan Isaac aisaac at american.edu
Fri Jan 25 18:41:08 EST 2008


bearophileHUGS at lycos.com wrote:
> I'd use the first solution.

It can be speeded up a bit with
a try/except:

for k,v in kv:
    try:
        if d[k] > v:
            d[k] = v
    except KeyError:
        d[k] = v

Cheers,
Alan Isaac



More information about the Python-list mailing list