- 編寫一段代碼,根據(jù)另一個列表中的值從一個列表中獲取值并打印輸出文本#基本列表: list1 = [1, 7, 5, 2, 10, 34, 621, 45, 7, 76, 23, "a", 14, 6]#從基本列表中排除 list2 = ['a', 'b', 'c', 7, 10, 23, 14]正確答案: List1 丟失了 6 個元素,現(xiàn)在有 8 個元素我的代碼:lost=0for i in list1: if i in list2: list1.remove(i) lost+=1print("List1 lost {} elements and now has {} elements".format(lost,len(list1)))運行代碼后,我打印了列表 1,這就是答案:列表 1 = [1, 5, 2, 34, 621, 45, 76, 'a', 6]為什么 'a' 沒有從 list1 中排除?
添加回答
舉報
0/150
提交
取消