runtime
368 / 500
question 368 Profiling & Optimization · medium

Copy the matching lines of a huge log

Support needs every line about one customer from a log too big for memory. Write copy_matching(source, target, needle): stream source, write each line that contains needle to target (unchanged, newline included), and return how many lines were copied. The hidden test measures the peak memory on a 60,000-line log.

Functioncopy_matching(source, target, needle)
Returnsthe number of lines written
Constraintopen each file once; peak memory under 1 MB for a 60,000-line source (about 1.7 MB)

Loading your progress…

Copy the matching lines of a huge log — Python practice · Runtime