4 ms·
Yes, but since it's an expression it is very verbose for a simple assignment. Python really needs something like: {foo: "default", mapping} = mapping
by BiteCode_dev 4y ago
Yes, but since it's an expression it is very verbose for a simple assignment.
Python really needs something like:
{foo: "default", mapping} = mapping
- d0mine 4y agoYou might want: foo = mapping.pop("foo", "default") It removes "foo" key from mapping if any. `foo` is "default" if "foo" is missing and `mapping["foo"]` otherwise. Dictionary unpacking compatible with the match/case syntax could look like: {"foo": foo, **rest} = mapping It asserts that there is "foo" key in mapping and puts its value into `foo`.