Python Tip #309 (of 365): Match dictionaries by their keys with match-case. >>> ...
Trey Hunner ๐ @treyhunner@mastodon.social
Python Tip #309 (of 365):
Match dictionaries by their keys with match-case.
>>> response = {"type": "rectangle", "width": 3, "height": 4}
>>> match response:
... case {"type": kind}:
... print(f"Object is {kind}")
... case {"error": message}:
... print(f"Error: {message}")
... case _:
... print("Unknown response")
...
Object is rectangle
๐งต (1/3)