推 robert09080: 這不是一個很好的寫法,因為你使用t2做迴圈,又刪除 02/24 11:57
→ robert09080: t2中的元素 02/24 11:57
→ robert09080: 請用 list comprehensive,[x for x in t2 if x no 02/24 11:58
→ robert09080: t in t1] 02/24 11:58
→ robert09080: 或是可以使用set,set(t2)-set(t1) 02/24 12:00
→ yrabes: 喔喔 我懂您的意思了!!感謝您~ 02/24 12:08
推 LeFilsDuVent: 至於為什麼會得到那個結果,test2[:]會是test2的一 02/24 15:30
→ LeFilsDuVent: shallow copy,所以你的loop的確會跑遍x=1,2,...,9 02/24 15:31
→ LeFilsDuVent: 但如果用for x in test2:那會跑的是x=1,3,5,7,9原因 02/24 15:32
→ LeFilsDuVent: 就如同樓上解釋的,你在loop through test2同時又修 02/24 15:32
→ LeFilsDuVent: 改test2 02/24 15:32
→ yrabes: 感謝,這樣說我更清楚了!! 02/24 15:55