1、通过set方法进行去重
a=[1,2,3,1,1,9,5,3]
print(set(a))
2、通过fromkeys方法创建新的字典
a = [1, 2, 3, 1, 1, 1, 7, 9, 5]
b = {}
# fromnkeys 创建一个新的字典,已a中的元素作为字典的键
b = b.fromkeys(a)
print(b) # {1: None, 2: None, 3: None, 7: None, 9: None, 5: None}
c = list(b.keys())
print(c) # [1, 2, 3, 7, 9, 5]
3、逻辑判断
a = [1, 2, 3, 1, 1, 1, 7, 9, 5]
b = []
for i in a:
if i not in b:
b.append(i)
print(b) # [1, 2, 3, 7, 9, 5]