
3 Feb
2022
3 Feb
'22
10:53 p.m.
On Thu, Feb 3, 2022 at 11:51 AM Yurii Karabas 1998uriyyo@gmail.com wrote:
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: {c: 3, d: 4}
Can't you solve the same problem with structural pattern matching against mappings? https://www.python.org/dev/peps/pep-0622/#mapping-patterns
Piper Thunstrom Senior Software Engineer/Open Source Maintainer