[Python-Dev] Analog of PEP 448 for dicts (unpacking in assignment with dict rhs)

Ben Usman bigobangux at gmail.com
Sun Nov 12 14:43:11 EST 2017


Anyway, considering that this has been discussed a lot in the original post
in 2016, I suggest stopping any further discussions here to avoid littering
dev mailing list. Sorry for starting the thread in the first place and
thank you, Jelle, for pointing me to the original discussion.

On Nov 12, 2017 14:33, "Ben Usman" <bigobangux at gmail.com> wrote:

Sounds like that happens quite often.

Yep, I totally agree with your point, I think I mentioned something like
this in the post as a possible partial solution: a drop-in replacement for
an ugly list compression people seem to be using now to solve the problem.
It's easy to implement, but the adoption by community is questionable. I
mean, if this is a relatively rare use case, but those who need it seem to
have their own one-liners for that already, is there even a need for a
method or function like this in standard library? To unify to improve
readability (single standard "getitems" instead of many different get_n,
gets, get_mutliple)? The only motivation I can think of, and even it is
questionable.

On Nov 12, 2017 05:06, "Nick Coghlan" <ncoghlan at gmail.com> wrote:

On 11 November 2017 at 16:22, Jelle Zijlstra <jelle.zijlstra at gmail.com>
wrote:
> 2017-11-10 19:53 GMT-08:00 Ben Usman <bigobangux at gmail.com>:
>> I was not able to find any PEPs that suggest this (search keywords:
>> "PEP 445 dicts", "dictionary unpacking assignment", checked PEP-0),
>> however, let me know if I am wrong.
>>
> It was discussed at great length on Python-ideas about a year ago. There
is
> a thread called "Unpacking a dict" from May 2016.

I tend to post this every time the topic comes up, but: it's highly
unlikely we'll get syntax for this when we don't even have a builtin
to extract multiple items from a mapping in a single operation.

So if folks would like dict unpacking syntax, then a suitable place to
start would be a proposal for a "getitems"  builtin that allowed
operations like:

    b, a  = getitems(d, ("b", "a"))

operator.itemgetter and operator.attrgetter may provide some
inspiration for possible proposals.

Cheers,
Nick.

--
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20171112/4c704a1f/attachment.html>


More information about the Python-Dev mailing list