Friday, April 19, 2013

Python Expressions: Merging Dictionaries

It's common in Python programming to need to merge 2 or more dictionaries together.

The first idiom is using the dict constructor. This idiom has it's limitations, however it will always work fine as long as the keys are all strings. Trying this with non-string keys will fail in Python 3.2 and later, and also fails in alternate Python implementations. The idiom itself is frowned upon.