Optimize function similiar to dict.update() but adds common values
Peter Otten
__peter__ at web.de
Wed Dec 14 12:20:58 EST 2005
Gregory Piñero wrote:
> Here's a question about your functions. if I only look at the keys in
> freq2 then won't I miss any keys that are in freq1 and not in freq2?
No. As I start with a copy of freq1, all keys of freq1 are already there.
There is probably a loop involved, but it in Python's underlying C
implementation, which is a bit faster.
What is left to do is to (1) add key and value for the 20% of freq2 that are
not in freq1, and to (2) increase the value for the 80% where the key
occurs in both freq1 and freq2. This is done by the for-loop.
Peter
More information about the Python-list
mailing list