Drill

ProblemsPython › logistics

Which zone price applies

easylogisticsPython

A carrier prices by zone. Look up the per-kilogram rate for a zone; a zone with no entry means it is not served.

zone_rate(zone_rates: map<string, int>, zone: string) → int

Solve it in the editor →

Where you start

def zone_rate(zone_rates: dict[str, int], zone: str) -> int:
    

Worked examples

CallResult
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)

The same problem in another language

More logistics problems in Python