How to make a copy of chained dicts effectively and nicely?

MRAB python at mrabarnett.plus.com
Tue Sep 27 10:39:27 EDT 2016


On 2016-09-27 08:32, Jussi Piitulainen wrote:
[snip]

> Is ChainMap really that bad? Otherwise the following would look somewhat
> nice:
>
> d = dict(ChainMap(d1, d2, d3).items())
>
> Those come to mind.
>
You can copy a dict just by passing it to 'dict':

     d = dict(d1)

so I wondered if you can do the same with ChainMap:

     d = dict(ChainMap(d1, d2, d3))

Yep, you can!




More information about the Python-list mailing list