可以通过以下两种方法删除列表中的重复元素:
my_list = [1, 2, 3, 3, 4, 5, 5, 6]
new_list = list(set(my_list))
print(new_list)
输出结果:[1, 2, 3, 4, 5, 6]
my_list = [1, 2, 3, 3, 4, 5, 5, 6]
new_list = []
[new_list.append(x) for x in my_list if x not in new_list]
print(new_list)
输出结果:[1, 2, 3, 4, 5, 6]
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
相关推荐:python列表重复元素怎么删除