1. 程式人生 > >python set函式,去除列表重複元素

python set函式,去除列表重複元素

正如標題所說,set函式可以非常方便的將一個列表去重,例如

a = [1,2,3,4,4,2,3,31,3,3,2,4,313,1,21,21,3,3,22,2,2,2,3,3,3,4,4]
b = set(a)
print(a)
print(b)輸出為[1, 2, 3, 4, 4, 2, 3, 31, 3, 3, 2, 4, 313, 1, 21, 21, 3, 3, 22, 2, 2, 2, 3, 3, 3, 4, 4] {1, 2, 3, 4, 21, 22, 313, 31}