4 ms·
True, although pattern-matching is unfortunately based on statements, which makes it less useful than if it were an expression (e.g. it can't be used in 'lambda
by chriswarbo 3y ago
True, although pattern-matching is unfortunately based on statements, which makes it less useful than if it were an expression (e.g. it can't be used in 'lambda', can't be used in function arguments, can't be used in a dictionary definition, can't be assigned to a variable, can't be used in generator/comprehension, etc.).
Also, Python requires explicit returns (unless we're in a lambda), so using a `match` statement for the above example would need multiple duplicate statements (either `return`, or assignment to a repeated variable name, or calling a repeated continuation (although that's less common, due to Python not eliminating tail calls), etc.). A chain of `elif` would also have that problem.