runtime
444 / 500
question 444 Data Formats & Analytical Workflows · easy

The largest fare, chunk by chunk

Write largest_fare(path, chunksize): read the trips CSV in chunks (only trip_id and fare_amount) and return (trip_id, fare_amount) for the trip with the largest fare. On a tie, return the trip that appears first in the file. An empty file gives None.

Functionlargest_fare(path, chunksize)
Returnsa tuple (trip_id, fare), or None
Examples
calllargest_fare('trips.csv', 4)returns(16132, 42.9)
calllargest_fare('trips.csv', 14)returns(16132, 42.9)
calllargest_fare('late.csv', 1)returns(3, 99.5)

Loading your progress…

The largest fare, chunk by chunk — Python practice · Runtime