unique¶
-
utils.
unique
(seq, idfun=None)[source]¶ Finds the unique items in a list and returns them in order found.
Inspired by discussion on
http://www.peterbe.com/plog/uniqifiers-benchmark
Notably f10 Andrew Dalke and f8 by Dave KirbyParameters: - seq (an iterable object) – The sequence from which the unique list will be compiled
- idfun (function, optional) – A hashing function for transforming the items into the form that is to
be compared. Default is the
None
Returns: result – The list of unique items
Return type: Examples
>>> a=list('ABeeE') >>> unique(a) ['A', 'B', 'e', 'E']
>>> unique(a, lambda x: x.lower()) ['A', 'B', 'e']
Note
Unless order is needed it is best to use list(set(seq))