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