Method One: Is the use of map Fromkeys from the dynamic filtering duplicate values, map is based on hash, large array should be faster than the sort of
Method Two: is set (), set is the definition of the set, unordered, non-repeating
Method Three: Is sorted after, backwards scan, encountered the existing elements deleted
============================================================
#!/usr/bin/python
#coding =utf-8
‘‘‘
Created on 2012-2-22
Q: Given a list, remove its duplicate elements and output
‘‘‘
Def distFunc1 ():
a=[1,2,4,2,4,5,6,5,7,8,9,0]
b={}
B=b.fromkeys (a)
Print B
#print B.keys ()
A=list (B.keys ())
Print a
Def DISTFUNC2 ():
a=[1,2,4,2,4,5,7,10,5,5,7,8,9,0,3]
A=list (Set (a)) # set is a non-repeating, unordered collection. You can sort the set by using list to queue, list () to A.sort,
Print a
Def distFunc3 ():
#可以先把list重新排序, and then from the last scan of the list, the code looks like this:
list=[1,2,4,2,4,5,7,10,5,5,7,8,9,0,3]
If List:
List.sort ()
#print List
Last = List[-1]
#print Last
For I in range (len (List)-2,-1,-1):
If Last==list[i]:
Del List[i]
Else:last=list[i]
if __name__ = = ' __main__ ':
DISTFUNC1 ()
DISTFUNC2 ()
DISTFUNC3 ()
Python code implementation Deletes a list of repeating elements