python去除列表中的空字符串
时间: 2023-10-10 09:08:55 浏览: 46
您好,针对您的问题,可以使用Python的列表推导式来去除列表中的空字符串。具体代码如下:
```
original_list = ["hello", "", "world", "", " ", "AI", " "]
new_list = [word for word in original_list if word.strip()]
print(new_list)
```
运行结果为:
```
['hello', 'world', 'AI']
```
这样就将原始列表中的空字符串以及只包含空格的字符串都去除了。