为什么我的代码不删除列表中的最后一个空元素?
templist = ['', 'hello', '', 'hi', 'mkay', '', '']
for element in templist:
if element == '':
templist.remove(element)
print (templist)
输出:
['hello', 'hi', 'mkay', '']
原文由 Clone 发布,翻译遵循 CC BY-SA 4.0 许可协议
好吧,你总是可以这样做: