Validating set

Here are some of the operations that can be performed to validate sets using Python as programming language.

  • Checking if an element exists (using in operator).

  • issubset - checking if first set is subset of second set

  • issuperset - checking if first set is superset of second set

  • isdisjoint - check if 2 sets have common elements

s = {1, 2, 3, 3, 4, 4, 4, 5}
1 in s
True
s1 = {1, 2, 3}
s2 = {1, 2, 3, 4, 5}
s1.issubset?
Docstring: Report whether another set contains this set.
Type:      builtin_function_or_method
s1.issubset(s2)
True
s1.issuperset(s2)
False
s2.issuperset(s1)
True
s1.issuperset(s2)
False
s1.isdisjoint?
Docstring: Return True if two sets have a null intersection.
Type:      builtin_function_or_method
s1 = {1, 2, 3, 4}
s2 = {3, 4, 5, 6, 7}
s1.isdisjoint(s2)
False
s1 = {1, 2, 3, 4}
s2 = {5, 6, 7}
s1.isdisjoint(s2)
True