r/smallprog • u/xamdam • Mar 12 '10
[Python] maximal column length in a csv file
#added context
import csv
f = open(fname, 'r')
lines = [l for l in csv.reader(f)]
#
print reduce(lambda s1, s2:map(max, zip(s1, s2)), [map(len, l) for l in lines])
8
Upvotes
3
u/nilsph Mar 12 '10
Doesn't work here:
General note: A bit of an explanation of how the oneliners are supposed to work would be nice. Oneliners are often not that easy to understand.
3
u/recursive Mar 12 '10
I eliminated about 40 chars for you:
Actually, here's about 20 more:
1
u/adavies42 Mar 12 '10 edited Mar 12 '10
k4: |/'#:''+((#","\:d)#"";,",")0:d:0:f