主要尝试了3种列表去除重复元素
#2.去除列表中的重复元素
#set方法
def removeDuplicates_set(nums):
l2 = list(set(l1))
#用l1的顺序排序l2
#l2.sort(key=l1.index)
return l2
#重构字典方法
def removeDuplicates_dict_fromkeys(nums):
l2 = {}.fromkeys(nums).keys()
return list(l2)
#列表推到式,普通方法
def removeDuplicates_normal(nums):
l2 = []
[l2.append(i) for i in nums if not i in l2]
return list(l2) if __name__=='__main__':
l1 = ['b','c','d','b','c','a','a']
print (removeDuplicates_normal(l1))