question 314 Iterators & Generators · easy
Stream the trip file instead of loading it
longest_trip(path) finds the trip with the greatest distance in a TLC trip CSV. It works, but it loads every row into a list first, and the full January file has millions of rows. Refactor it to read the file one row at a time, keeping exactly the same results: the first trip wins a tie, and a file with no trips gives None.
Function
longest_trip(path)Returns
(trip_id, miles) of the longest trip, as text and float; None for no tripsMemorydon't hold all rows: the check compares peak memory on a 60,000-row file with the file's size