Multiplying all the values in a dictionary

JW John-Whitlock at ieee.org
Fri Mar 24 10:39:41 EST 2006


As long as you are optimizing, addition is slightly faster than
multiplication:

$ python2.4 -mtimeit 'h=1;h*=2'
1000000 loops, best of 3: 0.286 usec per loop

$ python2.4 -mtimeit 'h=1;h=h+h'
1000000 loops, best of 3: 0.23 usec per loop

Of course, that's only a 20% decrease, so it might not be worth the
trouble.




More information about the Python-list mailing list