2. set Methods

2.1. set.isdisjoint()

  • No common elements

{1,2}.isdisjoint({3,4})     # True

2.2. set.issubset()

  • All elements in both

{1,2} <= {3,4}              # False
{1,2} <= {1,2}              # True
{1,2} <= {1,2,3}            # True
{1,2} < {1,2,3}             # True
{1,2} < {1,2}               # False

2.3. set.issuperset()

  • All elements of b are in a

{1,2} > {1,2,3}             # False
{1,2} > {1,2}               # False
{1,2,3} > {1,2}             # True
{1,2} >= {1,2}              # True
{1,2,3} >= {1,2}            # True

2.4. set.union()

  • add

{1,2} | {1,2}               # {1, 2}
{1,2,3} | {1,2}             # {1, 2, 3}
{1,2,3} | {1,2,4}           # {1, 2, 3, 4}
{1,2} | {1,3} | {2,4}       # {1, 2, 3, 4}

2.5. set.difference()

  • subtract

{1,2} - {2,3}               # {1}
{1,2} - {2,3} - {3}         # {1}
{1,2} - {1,2,3}             # set()

2.6. set.symmetric_difference()

  • not common elements from each

{1,2} ^ {1,2}               # set()
{1,2} ^ {2,3}               # {1, 3}
{1,2} ^ {1,3}               # {2, 3}

2.7. set.intersection()

  • common element from each

{1,2} & {2,3}               # {2}
{1,2} & {2,3} & {2,4}       # {2}
{1,2} & {2,3} & {3}         # set()

2.8. Assignments

Todo

Create Assignments