# Replace an if/elif chain with dict-based dispatch

Canonical URL: <https://datadriven.io/problems/replace-an-ifelif-chain-with-dict-based-dispatch-create-a-c7d0b7a0>

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.

## Related

- [All practice problems](https://datadriven.io/problems)
- [Mock interview mode](https://datadriven.io/interview/replace-an-ifelif-chain-with-dict-based-dispatch-create-a-c7d0b7a0)
- [Python Interview Questions](https://datadriven.io/python-interview-questions)
- [Data Engineering Interview Prep Guide](https://datadriven.io/data-engineer-interview-prep)
- [Daily Challenge](https://datadriven.io/daily)

---

Source: DataDriven (https://datadriven.io). 100% free data engineering interview prep. Live code execution against Postgres 16, Python 3.11, and Spark sandboxes. No paywall, no premium tier, no signup gate.