words = ["a\n", "\n", "ok\n", "\n", ""] print([word.strip() for word in words if word.strip() != ""])
Standard input is empty
['a', 'ok']
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!