Peter Otten wrote: > > def add_freqs3(freq1, freq2): > total = dict(freq1) > for key, value in freq2.iteritems(): > try: > total[key] += value > except KeyError: > total[key] = value > return total >
Untested, but replacing the try/except pair with the following should be semantically equivalent and a bit faster: total[key] = total.get(key,0) + value -- http://mail.python.org/mailman/listinfo/python-list