less than 1 minute read

Set difference

Get difference of two sets:

Input

set1 = {10, 20, 30, 40, 80}  
set2 = {100, 30, 80, 40, 60} 
  
print("set1 - set2 : ", set1.difference(set2)) 
print("set2 - set1 : ", set2.difference(set1))  

Output

set1 - set2 : {10, 20}
set2 - set1 : {100, 60}

Leave a comment