Boredom statistics The following list of how many ways to go back to the end.
1. Collection
List (set (alist))
If you want to keep the order:
Import randomif __name__== ' __main__ ': a=[random.randint (0,10) for I in Xrange (Ten)] b=list (Set (a)) B.sort (Key=a.index)
2. Dictionaries
Mostly using the hash table feature
{}.fromkeys (alist). Keys ()
or write manually:
Import randomif __name__== ' __main__ ': a=[random.randint (0,10) for I in Xrange (Ten)] d={} for I in a: d[i ]=1 Print D.keys ()
3. Check the weight after sorting
Import randomif __name__== ' __main__ ': a=[random.randint (0,10) for I in Xrange (Ten)] a.sort () print [X for I, X in enumerate (a) if not I or x!=a[i-1]]
4.itertools.groupby
Import randomimport itertoolsif __name__== ' __main__ ': a=[random.randint (0,10) for I in Xrange (Ten)] A.sort () Print [x[0] for X in Itertools.groupby (a)]
5. Traverse
Import randomif __name__== ' __main__ ': a=[random.randint (0,10) for I in Xrange (Ten)] b=[] for i in a: if I Not in B: b.append (i)
or use reduce:
Import randomimport functoolsif __name__== ' __main__ ': a=[random.randint (0,10) for I in Xrange (Ten)] Functools.reduce (Lambda x,y:x if y in x else x+[y],[[],]+a)
Is there any other way?