[Python-ideas] Accepting multiple mappings as positional arguments to create dicts

Andrés Delfino adelfino at gmail.com
Thu Apr 12 09:46:20 EDT 2018


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. I
believe we are safe regarding compatibility issues, right?

What do you guys think?

On Wed, Apr 11, 2018 at 4:44 AM, Mike Miller <python-ideas at mgmiller.net>
wrote:

> Ok, we can haggle the finer details and I admit once you learn the syntax
> it isn't substantially harder.  Simply, I've found the dict() a bit easier
> to mentally parse at a glance.  Also, to add I've always expected multiple
> args to work with it, and am always surprised when it doesn't.
>
> Would never have thought of this unpacking syntax if I didn't know that's
> the way its done now, but often have to think about it for a second or two.
>
>
> On 2018-04-10 22:22, Chris Angelico wrote:
>
>> On Wed, Apr 11, 2018 at 2:44 PM, Steven D'Aprano <steve at pearwood.info>
>> wrote:
>>
>>> On Wed, Apr 11, 2018 at 02:22:08PM +1000, Chris Angelico wrote:
>>>
>>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180412/5ddce907/attachment.html>


More information about the Python-ideas mailing list