I'm trying to print out just the non-empty strings in a list. I can't seem to get the below to work, what am I doing wrong??
print item in mylist if item is not ""
The following is invalid syntax: print item in mylist if item is not ""
You could perhaps achieve what you want using a list comprehension:
>>> mylist = ["foo","bar","","baz"]
>>> print [item for item in mylist if item]
['foo', 'bar', 'baz']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With