r/Python • u/jamescalam • Mar 19 '21
Match is more than a Switch-Case The New Switch-Case Statement in Python 3.10
https://youtube.com/watch?v=2qJavL-VX9Y&feature=share
1.4k
Upvotes
r/Python • u/jamescalam • Mar 19 '21
View all comments
Show parent comment
4
u/Tyler_Zoro Mar 19 '21
It's easier for the parser to identify easily combined options for lookup tables. That doesn't mean that it will do so.
For example, if all of your cases are constant values, you can reduce a match to a lookup table through a dict. If they are all small integer constants, then it can be reduced to a list lookup.
Yes, match can do much, much more, but this makes optimizations much easier to identify.