On Thu, Apr 12, 2018 at 7:34 AM, Ed Kellett <e+python-id...@kellett.im>
wrote:

> On 2018-04-12 14:46, Andrés Delfino wrote:
> > Extending the original idea, IMHO it would make sense for the dict
> > constructor to create a new dictionary not only from several mappings,
> but
> > mixing mappings and iterables too.
> >
> > Consider this example:
> >
> > x = [(1, 'one')]
> > y = {2: 'two'}
> >
> > Now: {**dict(x), **y}
> > Proposed: dict(x, y)
> >
> > I think this extension makes the call ostensibly easier to read and grep.
>
> It allows for creating a flattened dict from an iterable of dicts, too,
> which I've occasionally wanted:
>
> >>> configs = {'a': 'yes'}, {'b': 'no'}, {'c': 3}
> >>> dict(*configs)
> {'a': 'yes', 'b': 'no', 'c': 3}
>
> versus:
>
> >>> dict(chain.from_iterable(c.items() for c in configs))
> {'a': 'yes', 'b': 'no', 'c': 3}


Yes, this all sounds totally reasonable.

-- 
--Guido van Rossum (python.org/~guido)
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to