本文介绍了如何使用Python删除循环中的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到了这样的文本:
"TEXT1";" TEXT2";"TEXT3";"TEXT4";"TEXT5 ";"";"TEXT6"
"TEXT7";" TEXT8";"TEXT9";"TEXT10";"TEXT11";"";"TEXT12"
我使用了网络抓取功能,并且想要删除空字符串-> [5].我怎样才能做到这一点?代码:
I used web-scraping and I want to delete the empty string --> [5].How can I do this in a loop?The code:
for record in table.find_all('tr', class_="mytable"):
temp_data = []
for data in record.find_all("td"):
temp_data.append(data.text.encode('latin-1'))
datatable.append(temp_data)
#how can I delete the [5] here?
推荐答案
如果要删除空字符串,则可以简单地使用它,
If you want to remove empty string then you can simply use this,
newlist = filter(None, oldlist)
这篇关于如何使用Python删除循环中的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!