溫馨提示×

python中怎么去掉重復數(shù)據(jù)

小億
109
2023-11-24 09:29:18
欄目: 編程語言

可以使用set()函數(shù)來去除重復數(shù)據(jù),set()函數(shù)會返回一個只包含不重復元素的集合。
例如,有一個包含重復元素的列表,可以使用set()函數(shù)來去除重復元素:

data = [1, 2, 3, 3, 4, 4, 5]
unique_data = list(set(data))
print(unique_data)

輸出結(jié)果為:

[1, 2, 3, 4, 5]

0