Ways to Join Sets

4 Operations to Join Sets

Situation: You have sets containing strings, you can join, find intersections, or differences and symmetric differences.

4 Operations

my_drinks = {'grape', 'cola', 'black cherry'}
her_drinks = {'lime', 'cola'}

# position if not retained in a set
print(my_drinks, her_drinks)

# 4 operations to know about

# union
print("Union", my_drinks | her_drinks)


# intersection
print("Intersection", my_drinks & her_drinks)

# difference
print("Difference", my_drinks - her_drinks)


# symmetric difference
print("Symmetric Difference", my_drinks ^ her_drinks)
   
Previous
Next