Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Jussi Piitulainen Newsgroups: comp.lang.python Subject: Re: Set Operations on Dicts Date: Mon, 08 Feb 2016 17:05:56 +0200 Organization: A noiseless patient Spider Lines: 16 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="305c68510616a2e7ac08bcd2ff1598bd"; logging-data="30944"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19kiJpBDWWLFoEUrurrfqwoBVu1U/m9nIE=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:dMVc6+wHmjMJhSclMfb/ePo11TE= sha1:zJ4N4L6fXflp1fNa85sNnJ4NtQA= Xref: csiph.com comp.lang.python:102675 Random832 writes: > On Mon, Feb 8, 2016, at 08:32, Matt Wheeler wrote: >> On 8 February 2016 at 12:17, Jussi Piitulainen wrote: >> > Also, what would be the nicest current way to express a priority union >> > of dicts? >> > >> > { k:(d if k in d else e)[k] for k in d.keys() | e.keys() } >> >> Since Python 3.5: {**e, **d} > > And before that... dict(ChainMap(d, e)) New in version 3.3. Thanks, I didn't know of that either. Reading the docs, I think for the use I had in mind, ChainMap(d, e) itself would suffice.