如何删除海峡。列表中的空格
How to remove str. Of spaces from list
A = ["a","b","",c","","d"]
我怎样才能删除海峡。此列表中的空格
A = [s for s in A if s.strip() != '']
或
A = [s for s in A if len(s.strip()) > 0]
A = [s for s in A if s.strip()]
以上代码有效,因为空字符串 - 即 '' - 评估为 False。
A = ["a","b","",c","","d"] 我怎样才能删除海峡。此列表中的空格
A = [s for s in A if s.strip() != '']
或
A = [s for s in A if len(s.strip()) > 0]
A = [s for s in A if s.strip()]
以上代码有效,因为空字符串 - 即 '' - 评估为 False。