[Python-ideas] Mapping unpacking assignment

2022-02-03 Thread Stephen J. Turnbull
Yurii Karabas writes: > I am proposing to add smth like JS destructing assignment to python. > Basically, it will allow unpacking any mapping (should have > __getitem__ and keys() methods) into variables. Ideas like this have been suggested before, with a number of variations on syntax (specif

[Python-ideas] Mapping unpacking assignment

2022-02-03 Thread Yurii Karabas
I am proposing to add smth like JS destructing assignment to python. Basically, it will allow unpacking any mapping (should have __getitem__ and keys() methods) into variables. Proposed syntax: ``` m = {"a": 1, "b": 2, "c": 3, "d": 4} {a, b} = m # a: 1, b: 2 {a, b, **rest} = m # a: 1, b: 2, rest