Combine two dictionary...

Raymond Hettinger python at rcn.com
Mon Oct 1 13:51:07 EDT 2007


On Oct 1, 10:24 am, Abandoned <best... at gmail.com> wrote:
> Hi..
> dict1={1: 4,  3: 5}... and 2 millions element
> dict2={3: 3,  8: 6}... and 3 millions element
>
> I want to combine dict1 and dict2 and i don't want to use FOR because
> i need to performance.

The dict.update approach is the fastest way to build a combined
dictionary; however, it may be much cheaper to logically combine the
dictionaries rather than spending the time and memory to build a
physically combined dictionary:   http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/305268

Raymond




More information about the Python-list mailing list