Return True if there are only whitespace characters in the string and there is at least one character, False otherwise.
A character is whitespace if in the Unicode character database (see unicodedata), either its general category is Zs (“Separator, space”), or its bidirectional class is one of WS, B, or S.
import re
r = re.compile(r"^\s+")
dirty_list = [...]
# iterate over dirty_list substituting
# any whitespace with an empty string
clean_list = [
r.sub("", s)
for s in dirty_list
]
你应该能够使用这个
因为如果你阅读^{} 的文档,它会说:
如果您查看类别
Zs
的unicode character list在这种情况下,Regex是您的朋友,您可以简单地应用Regex替换来迭代列表
相关问题 更多 >
编程相关推荐