Linux 拨号vps windows公众号手机端

python如何去除list中重复的数据

lewis 8年前 (2017-11-12) 阅读数 5 #程序编程
文章标签 python

可以使用set()函数去除list中的重复数据。具体的做法是先将list转化为set,然后再将set转化为list。示例代码如下:

list_with_duplicates = [1, 2, 3, 4, 2, 3, 5, 1]
list_without_duplicates = list(set(list_with_duplicates))
print(list_without_duplicates)

输出结果为:[1, 2, 3, 4, 5]

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门