plastid.util.services.sets module

Utilities for handling sets.

Exported functions

merge_sets()
Recursively merge of sets based upon common members, until all groups sharing common members are merged.
get_random_sets()
Generate random sets of members
plastid.util.services.sets.get_random_sets(num_sets, 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

Parameters:
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)

Returns:
list

List of generated sets

plastid.util.services.sets.merge_sets(list_of_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

Parameters:
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)

Returns:
list

list of merged sets