All Projects → nvie → dictmerge

nvie / dictmerge

Licence: other
Merge dicts without mutating them.

Programming Languages

python
139335 projects - #7 most used programming language

dictmerge

Merge dicts without mutating them.

>>> d1 = {'a': 1}
>>> d2 = {'b': 2}
>>> dictmerge(d1, d2, moar=3)
{'a': 1, 'b': 2, 'moar': 3}

As of Python 3.5 you can use the following syntax for this purpose:

>>> d1 = {'a': 1}
>>> d2 = {'b': 2}
>>> {**d1, **d2}
{'b': 2, 'a': 1}
>>> {**d1, **d2, 'moar': 3}
{'b': 2, 'moar': 3, 'a': 1}

Installation

$ pip install dictmerge
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].