3 ms·
there is a pattern matching in Python 3.10 (match/case) which can match dictionaries. https://peps.python.org/pep-0636/#going-to-the-cloud-mappings https://pep
by d0mine 4y ago
there is a pattern matching in Python 3.10 (match/case) which can match dictionaries.
https://peps.python.org/pep-0636/#going-to-the-cloud-mappings https://peps.python.org/pep-0636/#going-to-the-cloud-mapping...
- BiteCode_dev 4y agoYes, 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`.