【发布时间】:2021-10-04 15:52:43
【问题描述】:
A = ["a","b",","c",",","d"] 我怎样才能删除str。此列表中的空格????
【问题讨论】:
标签: python string list helper spaces
A = ["a","b",","c",",","d"] 我怎样才能删除str。此列表中的空格????
【问题讨论】:
标签: python string list helper spaces
A = [s for s in A if s.strip()]
上述代码有效,因为空字符串 - 即 '' - 评估为 False。
【讨论】:
A = [s for s in A if s.strip() != '']
或
A = [s for s in A if len(s.strip()) > 0]
【讨论】: