python:列表的去重:两种方法的问题是:结果是没有保持原来的顺序。

列表的去重

1、使用set的特型,python的set和其他语言类似, 是一个无序不重复元素集

orgList = [1,0,3,7,7,5]
#list()方法是把字符串str或元组转成数组
formatList = list(set(orgList))
print (formatList)

2、使用keys()方法

orgList = [1,0,3,7,7,5]
#list()方法是把字符串str或元组转成数组
formatList = list({}.fromkeys(orgList).keys())
print (formatList)
原文地址:https://www.cnblogs.com/zack-dong/p/11965496.html