Which zone price applies
A carrier prices by zone. Look up the per-kilogram rate for a zone; a zone with no entry means it is not served.
- Rates are per kilogram, in minor units.
- A zone that is not in the table is unsupported: return 0.
zone_rate(zone_rates: map<string, int>, zone: string) → int
Where you start
def zone_rate(zone_rates: dict[str, int], zone: str) -> int:
Worked examples
| Call | Result |
|---|---|
zone_rate({"a": 120, "b": 180, "c": 250}, "a") | 120 |
zone_rate({"a": 120, "b": 180}, "c") | 0 |
zone_rate({}, "a") | 0 |
zone_rate({"x": 0}, "x") | 0 |
Hint
Map lookup, then a default.
Reference solution in Python
def zone_rate(zone_rates: dict[str, int], zone: str) -> int:
return zone_rates.get(zone, 0)