I’m not sure this is needed, since the optimizer might take care of it but the question is about:
JavaScript
x
2
1
[ x.strip() for x in f.readlines() if x.strip() ]
2
both sides need the strip, (just ‘if x’ is not enough).
Advertisement
Answer
I suggest using map
:
JavaScript
1
2
1
[ x for x in map(str.strip, f.readlines()) if x ]
2