collections

New in version 1.1.0.

Collection utilities

smisk.util.collections.merge(a, b)

Updates collection a with contents of collection b, recursively merging any lists and dictionaries.

Lists are merged through a.extend(b), dictionaries are merged by replacing and non-list or dict key with the value from collection b. In other words, collection b takes precedence.

smisk.util.collections.merge_dict(a, b, merge_lists=True)

Updates dictionary a with contents of dictionary b, recursively merging any lists and dictionaries.

Lists are merged through a.extend(b), dictionaries are merged by replacing and non-list or dict key with the value from collection b. In other words, collection b takes precedence.

smisk.util.collections.merged(a, b)
Like merge but does not modify a
smisk.util.collections.merged_dict(a, b, merge_lists=True)
Like merge_dict but does not modify a
smisk.util.collections.unique(seq)

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"], and unique(([1, 2], [2, 3], [1, 2])) some permutation of [[2, 3], [1, 2]].

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 raise TypeError it’s assumed that they do enjoy a total ordering. Then unique() will usually work in O(N*log2(N)) time.

If that’s not possible either, the sequence elements must support equality-testing. Then unique() will usually work in quadratic time.

Parameters:
  • seq (collection) –
Return type:

list

smisk.util.collections.unique_wild(seq)
Parameters:
  • seq (collection) –
Return type:

list