Python代碼這么寫有什么錯誤?
s?=?set(['Adam','Lisa','Paul']) L?=?['Adam','Lisa','Bart','Paul'] for?x?in?L: ????for?y?in?s:?? ????????if?x==y: ????????????s.add(x) ????????else?:? ????????????s.remove(x) print?(s)
s?=?set(['Adam','Lisa','Paul']) L?=?['Adam','Lisa','Bart','Paul'] for?x?in?L: ????for?y?in?s:?? ????????if?x==y: ????????????s.add(x) ????????else?:? ????????????s.remove(x) print?(s)
2017-02-27
舉報
2017-03-31
set 是無序的,你這樣寫,會導致結果存在誤差,不斷地被取出又被放回
2017-02-28
同新手。?!甋et changed size during iteration ’ 應該是在對s迭代的時候不能夠改變s