[Python-ideas] Yet More Unpacking Generalizations (or, Dictionary Literals as lvalues)

random832 at fastmail.us random832 at fastmail.us
Wed Aug 12 17:41:18 CEST 2015


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)


More information about the Python-ideas mailing list