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} ``` It will be rawly equal to: ``` m = {"a": 1, "b": 2, "c": 3, "d": 4} # {a, b} = m a = m["a"] b = m["b"] # {a, b, **rest} rest = {**m} a = rest.pop("a") b = rest.pop("b") ``` This is fully backward compatible feature because currently syntax like above is not supported: ``` {a, b} = m # a: 1, b: 2 ^^^^^^ SyntaxError: cannot assign to set display here. Maybe you meant '==' instead of '='? ``` _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/XWYDTMI7HVVDBENMFAAFQNAIHTDPUCUZ/ Code of Conduct: http://python.org/psf/codeofconduct/