1 l1 = [1, 2, 3, 4, 2, 2, 3, 4, 55, 66] 2 l2 = list() 3 # 取出l1的元素 4 for i in l1: 5 # 判断取出的元素是否在l2 6 if i not in l2: 7 # 不在的话追加进l2 8 l2.append(i) 9 print(l2)
1 l1 = [1, 2, 3, 4, 2, 2, 3, 4, 55, 66] 2 l2 = list() 3 # 取出l1的元素 4 for i in l1: 5 # 判断取出的元素是否在l2 6 if i not in l2: 7 # 不在的话追加进l2 8 l2.append(i) 9 print(l2)