Utilities for handling sets.

Exported functions

Recursively merge of sets based upon common members, until all groups sharing common members are merged.
Generate random sets of members, max_len=3, members=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p'])[source]

Generates random sets of members

num_sets : int

number of sets to generate

max_len : int

maximum length for each set

members : list-like

Sequence of hashable members to put in each set (Default: letters a-p)


List of generated sets, printer=None)[source]

Merges sets in a list if they have one or more common member, until all groups sharing common members are merged.

Merging takes places as follows:

  1. All members in all sets are counted
  2. All sets containing more than one member are merged via a call to _merge_sets()
  3. A set of unmerged single-member sets is generated by finding all members that appear in multi-member sets after step (2), and subtracting this set from the set generated in step (1)
  4. The list of single- and multi-member sets are concatenated to create a final list

Repeat steps 1-4 until the number of sets is unchanged

list_of_sets : list

List of sets of hashable items

printer : file-like, or None

Writer to which status is sent, as string, if not None (Default: None)


list of merged sets