4 ms·
Python doesn't have a case statement but (as of 3.10) it does have match. The apparent problem with using either of those is that you'd potentially have to eval
by staplung 3y ago
Python doesn't have a case statement but (as of 3.10) it does have match. The apparent problem with using either of those is that you'd potentially have to evaluate many, many if statements (or match clauses) in the worst case whereas with the hand-made binary tree you'll only have to do 8 checks.
Having said that, I too wonder why they didn't use a dictionary. ;-)