collections
Collection utilities.
smisk.util.collections.unique_wild(seq)-
Parameters seq (collection) Return type list Return unique elements of seq using equality testing. Works for any element type, including unhashable and unorderable items (O(N²) worst case).
smisk.util.collections.unique(seq)-
Parameters seq (collection) Return type list Return a list of the elements in seq, but without duplicates.
For example,
unique([1,2,3,1,2,3])is some permutation of[1,2,3],unique("abcabc")some permutation of["a", "b", "c"].For best speed, all sequence elements should be hashable. Then
unique()will usually work in linear time.If not possible, the sequence elements should enjoy a total ordering, and if
list(s).sort()doesn't raiseTypeErrorit's assumed that they do enjoy a total ordering. Thenunique()will usually work in O(N·log₂N) time.If that's not possible either, the sequence elements must support equality-testing. Then
unique()will usually work in quadratic time.