Package tulip :: Package transys :: Module mathset
[frames] | no frames]

Module mathset

Mathematical Sets and Power Sets

Classes
  MathSet
Mathematical set, allows unhashable elements.
  SubSet
Subset of selected MathSet, or other Iterable.
  CartesianProduct
List of MathSets, with Cartesian semantics.
  PowerSet
Efficiently store power set of a mathematical set.
  TypedDict
dict subclass where values can be constrained by key.
Functions
bool
compare_lists(list1, list2)
Compare list contents, ignoring ordering.
  • If all items in iterable are hashable, then returns set.
  • If iterable contains unhashable item, then returns list of unique elements.
unique(iterable)
Return unique elements.
 
contains_multiple(iterable)
Does iterable contain any item multiple times ?
 
is_subset(small_iterable, big_iterable)
Comparison for handling list <= set, and lists with unhashable items.
 
powerset(iterable)
powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)
Variables
  logger = logging.getLogger(__name__)
  __package__ = 'tulip.transys'
Function Details

compare_lists(list1, list2)

 

Compare list contents, ignoring ordering.

Hashability of elements not assumed, incurring O(N**2)

See Also

MathSet

Parameters:
  • list1 (list)
  • list2 (list)
Returns: bool
True if a bijection exists between the lists. Note that this takes into account multiplicity of elements.

unique(iterable)

 

Return unique elements.

Note

Always returning a list for consistency was tempting, however this defeats the purpose of creating this function to achieve brevity elsewhere in the code.

Returns:
  • If all items in iterable are hashable, then returns set.
  • If iterable contains unhashable item, then returns list of unique elements.
iterable with duplicates removed, as set if possible.

powerset(iterable)

 

powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)

From http://docs.python.org/2/library/itertools.html, also in https://pypi.python.org/pypi/more-itertools