runtime
492 / 500
question 492 Production Readiness Capstone · easy

The core that changes its input

with_boroughs adds pickup boroughs to trips for the report. Two problems surfaced in review: it writes into the caller's trip dictionaries (the API's cached trips suddenly have a borough field), and it ignores the zone table it is given, reading a global one instead, so tests with their own table fail. Make it pure: return new dictionaries and use only its arguments.

Functionwith_boroughs(trips, zones)
Returnsa new list of new dictionaries: each trip's fields plus borough (zones lookup of pickup_zone_id, "Unknown" if missing)
Rulethe trips are not changed; only the zones argument is used
Examples
callwith_boroughs([{'trip_id': 16126, 'pickup_zone_id': 186}, {'trip_id': 16128, 'pickup_zone_id': 39}], {186: 'Manhattan', 39: 'Brooklyn'})returns[{'trip_id': 16126, 'pickup_zone_id': 186, 'borough': 'Manhattan'}, {'trip_id': 16128, 'pickup_zone_id': 39, 'borough': 'Brooklyn'}]

Loading your progress…

The core that changes its input — Python practice · Runtime