Structural pattern matching is probably the coolest new syntax introduced to Python. Added in 3.10, it's been a few years now and more people are writing apps in 3.10* than any other version now.
Though even with the wide adoption of 3.10 and more people being exposed to the match
and case
syntax, I find still some resistance towards more advanced usage of it. This is natural as new syntax will always take time. Even something as simple as :=
walrus operator took some time for the community to warm up to it.
Given the massive potential of pattern matching, I thought it be good to compile a cookbook for it so that people can familiarise themselves with it. I once again created the cookbook using JupyterLite, and surprisingly I found a lot holes in my own knowledge of pattern matching.
So please read though it, play with it, copy it, create your own. It's okay to decide not to use all the features of pattern matching, but it's certainly good to build a knowledge base for yourself.
Cookbook
Same as before I've created a cookbook using JupyterLite in the web. You can interact with it here,
Browse my Cookbooks
My cookbooks are hosted statically here.
The source code can be found here.
Downloading the notebook
- Click the "JupyterLab" button above.
- In the file view, right click and select "Download"