返回顶部

python3去除列表中的空字符和\n

有时候在解析数据出来的时候总是会出现空格,回车\n,制表符\t,或者空,可尝试以下操作:

>>> list1 = ['hello,world!', ' ', '\n', '\t', '', 'I am here.']
>>> [x.strip() for x in list1 if x.strip()!='']
['hello,world!', 'I am here.']
>>>

  

 

posted @ 2021-07-20 10:37  Adrian·Ding  阅读(828)  评论(0编辑  收藏  举报