[Python-ideas] Yet More Unpacking Generalizations (or, Dictionary Literals as lvalues)
Joseph Jevnik
joejev at gmail.com
Wed Aug 12 17:46:10 CEST 2015
>From a language design standpoint I think that having non-constant keys in
the unpack map makes a lot of sense. As far as implementation, I would
imagine that using non-constant expressions for the keys should be fine. If
you look at the proposed implementation, the UNPACK_MAP instruction just
wants the stack to have N values on the stack, it shouldn't matter how they
got there.
On Wed, Aug 12, 2015 at 11:41 AM, <random832 at fastmail.us> wrote:
> On Wed, Aug 12, 2015, at 09:57, Scott Sanderson wrote:
> > def do_stuff_from_json(json_dict):
> > # Assigns variables in the **values** of the lefthand side by doing
> > lookups
> > # of the corresponding keys in the result of the righthand side
> > expression.
> > {'foo': foo, 'bar': bar} = json.loads(json_dict)
>
> How about:
>
> key = 'foo'
> key2 = 'bar'
> {key: value, key2: value2, **rest} = json.loads(json_dict)
> _______________________________________________
> 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/20150812/b7be12ab/attachment.html>
More information about the Python-ideas
mailing list