Dict merge in a dict comprehension
It’s not exactly an answer to your question but I’d consider using ChainMap to be an idiomatic and elegant way to do what you propose (merging dictionaries in-line): >>> from collections import ChainMap >>> d1 = {1: ‘one’, 2: ‘two’} >>> d2 = {3: ‘three’} >>> ds = [d1, d2] >>> dict(ChainMap(*ds)) {1: ‘one’, 2: … Read more