python - How to remove blank lines only and retain the order -


showowi  g exsu n  sierouz  nicee99 

this output after performing ocr using tesseract.the blank space varies in occurence times there multiple blanks between usernames none between usernames.i trying find solution strip these blank lines .i want strip them before writing file.how remove blank space retain them 1 below other using python.

i went through similar questions in regarding nothing seems tow work me.

what filtering lines:

lines = output.splitlines() filtered = [line line in lines if line.strip()] 

the if line.strip() implictly check line.strip() != "" (empty string falsy value).

of course, can done using functional way:

filtered = filter(lambda line: line.strip(), lines) 

and single string back:

new_output = '\n'.join(filtered) 

Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

minify - Minimizing css files -

php - How to remove letter in front of the word laravel -