有时候解析出来的数据存在太多的\n、\t、空字符等,这时就需要用到:
list1 = ['hello,world!',' \n ','Python','','\n','中国\n']
result = [x.strip() for x in list1 if x.strip()!='']
print(result)
运行结果:
['hello,world!', 'Python', '中国']
有时候解析出来的数据存在太多的\n、\t、空字符等,这时就需要用到:
list1 = ['hello,world!',' \n ','Python','','\n','中国\n']
result = [x.strip() for x in list1 if x.strip()!='']
print(result)
运行结果:
['hello,world!', 'Python', '中国']