Replace an if/elif chain with dict-based dispatch
A medium Python interview practice problem on DataDriven. Write and execute real python code with instant grading.
- Domain
- Python
- Difficulty
- medium
Problem
Replace an if/elif chain with dict-based dispatch. Create a dict mapping 'add' to a lambda that adds two numbers, 'sub' to subtract, and 'mul' to multiply. Use it to compute: add(10, 5), sub(10, 5), mul(10, 5). Print each result.
Practice This Problem
Solve this Python problem with real code execution. DataDriven runs your Python code in a real environment and grades it automatically.