How to remove empty string in a list?

前端 未结 9 1653
我在风中等你
我在风中等你 2020-12-28 17:42

For example I have a sentence

\"He is so .... cool!\"

Then I remove all the punctuation and make it in a list.

[\"He\", \"         


        
9条回答
  •  不思量自难忘°
    2020-12-28 18:43

    You can filter out empty strings very easily using a list comprehension:

    x = ["He", "is", "so", "", "cool"]
    x = [str for str in x if str]
    >>> ['He', 'is', 'so', 'cool']
    

提交回复
热议问题