python subtract one set from another

Solutions on MaxInterview for python subtract one set from another by the best coders in the world

showing results for - "python subtract one set from another"
Rodrigo
09 Jul 2019
1# Basic syntax:
2difference_of_sets = set_1 - set_2
3
4# Example usage:
5# Define sets
6set_1 = {3, 7, 11, 23, 42}
7set_2 = {1, 2, 11, 42, 57}
8# Return elements of set_1 that aren't in set_2:
9difference_of_sets = set_1 - set_2 
10print(difference_of_sets)
11--> {3, 23, 7}
12
13# Syntax for other set functions:
14set_1 | set_2 # Union of sets (elements in both)
15set_1 & set_2 # Intersection of sets (elements in common)