Matt Nordhoff wrote:
Chris Rebert wrote:
I personally would probably do:
from collections import defaultdict
label2sum = defaultdict(lambda: 0)
FWIW, you can just use:
label2sum = defaultdict(int)
You don't need a lambda.
Indeed, in this case, with two known keys, the defaultdict is not needed
either, since the following should work as well to initialize
label2sum = {'F1':0,'F2':0}
for r in rec:
for key, value in r.iteritems():
label2sum[key] += value
ratio = label2sum["F1"] / label2sum["F2"]
--
http://mail.python.org/mailman/listinfo/python-list