chicken_turtle_util.set

Set utilities. Contains only merge_by_overlap, merges overlapping sets in place.

merge_by_overlap Of a list of sets, merge those that overlap, in place.
chicken_turtle_util.set.merge_by_overlap(sets)[source]

Of a list of sets, merge those that overlap, in place.

The result isn’t necessarily a subsequence of the original sets.

Parameters:

sets : [{any}]

Sets of which to merge those that overlap. Empty sets are ignored.

Notes

Implementation is based on this StackOverflow answer. It outperforms all other algorithms in the thread (visited at dec 2015) on python3.4 using a wide range of inputs.

Examples

>>> merge_by_overlap([{1,2}, set(), {2,3}, {4,5,6}, {6,7}])
[{1,2,3}, {4,5,6,7}]