Inefficient summing

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Thu Oct 9 06:58:59 EDT 2008


FB:
> def add_r( sums, r ): return sums[0]+r['F1'], sums[1]+r['F2']
> sum_f1, sum_f2 = reduce( add_r, rec, (0,0) )
> result = sum_f1/sum_f2

Until this feature vanishes I think it's better to use it (untested):

add_r = lambda (a, b), r: (a + r['F1'], b + r['F2'])

Bye,
bearophile



More information about the Python-list mailing list