3 ms·
import csv r = csv.reader(open('file.csv')) first_row = r.next() for row in r: if row[0] == first_row[0]: return True r
by pstrateman 11y ago
import csv
r = csv.reader(open('file.csv'))
first_row = r.next()
for row in r:
if row[0] == first_row[0]:
return True
return False
287MB file 100m rows 15.804s peak memory usage 7MB
- xamuel 11y agoThank you, that is beautiful. I've been proved decisively wrong and I've gained some greater appreciation for python's libraries.
- TylerE 11y agoIt's not even a library thing. Reading a file in this way does reads in approximately optimal (for the FS) sized blocks. The CSV parser just rides on top of stdio.