If emptiness is an important result, it is best to check the source string first:
x = '' if x:
In the first test, empty start lines are excluded, the second using any excludes lines that are nothing more than a split character, and therefore returned a whole bunch of empty lines, but not non-empty lines. As long as you have one non-empty line, it goes through.
Note. If you are trying to parse CSV files, do not use .split(',') ; there is a csv module that handles this correctly (including escape sequences, quotation marks, etc.) and should ALWAYS be used to parse CSV, never collapse your own parser. Added bonus: csv converts '' entries to strings [] , which you can check for truth directly, and not [''] like str.split . Example:
>>> import csv, io >>> f = io.StringIO('\n\na,b,c\n1,2,3\n\n') >>> [row for row in csv.reader(f) if row]
vs. same approach with str.split(',') that still does not handle quotes, escaping, etc .:
>>> f = io.StringIO('\n\na,b,c\n1,2,3\n\n') >>> stripped = (line.rstrip('\r\n') for line in f) # Must manually strip line endings first >>> [line.split(',') for line in stripped if line] [['a', 'b', 'c'], ['1', '2', '3']]