python3去除列表中的空字符和

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

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

  

原文地址:https://www.cnblogs.com/ding2016/p/15033682.html