0
删除元素以正确的方式谷歌没有发现...... 我想两种解决方案:蟒蛇:whtat是从列表
1) How to remove an element in a for..in.. loop for a list?
2) How to remove all the elements in the list?
删除元素以正确的方式谷歌没有发现...... 我想两种解决方案:蟒蛇:whtat是从列表
1) How to remove an element in a for..in.. loop for a list?
2) How to remove all the elements in the list?
这是几乎从来没有你想要做什么。使用列表理解来过滤掉你不想要的项目。
del L[:]
1) filter()
2) list = []
1)在大多数情况下丑陋的,但不值得一downvote。 2)完全错误。它只是创建一个新列表并将其分配给'list'(唉),而不实际删除列表中的任何元素。 – aaronasterling 2010-11-13 12:46:54
是的,你是对的。 – 2010-11-13 12:51:07
此外,列表解析应该优先于filter() – helpermethod 2010-11-13 13:35:28