SyntaxFix
Write A Post
Hire A Developer
Questions
Try list comprehension and string.strip():
string.strip()
>>> mystr = "L1\nL2\n\nL3\nL4\n \n\nL5" >>> mystr.split('\n') ['L1', 'L2', '', 'L3', 'L4', ' ', '', 'L5'] >>> [line for line in mystr.split('\n') if line.strip() != ''] ['L1', 'L2', 'L3', 'L4', 'L5']