r/Python • u/Iron-Man-2008 • Aug 24 '26
Discussion TIL: Dict Patterns Don't Match Dict Shapes
TL;DR: Unlike sequence patterns (which require an exact shape match), pattern matching on dictionaries simply ignores any unspecified keys rather than failing.
If you care about the details, I wrote about it on my blog: https://ravencentri.cc/blog/dict-patterns-dont-match-dict-shapes/
40
Upvotes
View all comments
Show parent comment
2
u/Iron-Man-2008 Aug 29 '26
_in match case is actually a special wildcard pattern and does not bind to a name.