Onyx logo

Previous topic

onyx.util.capture – Proxy object for capturing expression values

Next topic

onyx.util.discrete – Tools for working with discrete spaces.

This Page

onyx.util.collate – Tools for simple collation tasks.

onyx.util.collate.collate_pairs(iterable)

Collate the iterable sequence of pairs, ((key, value), (key, value), ...). Returns a frozendict in which each key maps to the sequence of values that appeared with that key in the iteration. The collation is stable; that is, the order of the values in the list for a given key is the order in which those values appeared in the iteration.

>>> col = collate_pairs(((1, 2), (2, 0), (1, 1), (1, 2), ('a', 'b'), ('a', None)))
>>> for key in sorted(col.keys()): print key, col[key]
1 (2, 1, 2)
2 (0,)
a ('b', None)