Python 检查列表是否只包含空元素或空格

标签 python list boolean whitespace

我想检查一个列表是否只包含空元素或空格,比如:

l = ['','   ','\n']
if all(whitespace or empty for element in l):
    return True

有人知道怎么做吗?

最佳答案

那么你的空白就是str.isspace(..) 所以:

if all(<b>'' == s or s.isspace()</b> for s in l):
    return True

关于Python 检查列表是否只包含空元素或空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43261732/

相关文章:

python - Pandas 数据透视表不断返回 False 而不是 0

c# - C# boolean 函数并非所有代码都返回值

python - 在 Pyside2 for Python 上显示应用程序后如何刷新事件?

python - 字典列表 : aggregate value by grouping by inner dictionary key

list - 理解递归定义的列表(用 zipWith 表示的 fibs)

c - C 中的 stdbool.h bool 类型按位异或 ^ 和赋值

Python 无法导入嵌套层次结构中生成的扩展

python - 在 Python 队列中伪造一个插入

python - Django 表单和 Material Design Lite

arrays - 在Python中分配字节列表