一开始理解成L和S都有的数字,就从L中删除,把剩下的数字传给S,即L→L(2,4,6,8,10, S={1,2,3,4,5,6,7,8,9,10,11},就写了下面的代码,为什么用debug调试 ,num的数值只经过1,3,5,7,9,没有2,4,6,8?
L = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] S = set([1, 3, 5, 7, 9, 11]) for num in L: if num in S: L.remove(num) else: S.add(num) print(L) # L=[2, 4, 6, 8, 10] print(S) # S ={1, 3, 5, 7, 9, 11}