Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

How to Get the Difference Between Sets in Python

firstSet = {2, 3, 4, 5}

secondSet = {1, 3, 5, 7}

print(firstSet - secondSet)
# {2, 4}
Comment

difference() Function of sets in python

# The difference() function can be used to create a new set containing the difference
# from one set with another

mySet = {1, 2, 3, 4}
mySet2 = {3, 4, 5, 6}
mySet3 = mySet.difference(mySet2)
print(mySet3)

# Output:
# {1, 2}
Comment

PREVIOUS NEXT
Code Example
Python :: pandas apply function on two columns 
Python :: pyttsx3 set volume 
Python :: pytesseract.image_to_string save text file 
Python :: pylint import error 
Python :: python refresh import 
Python :: filter function in pandas stack overflow 
Python :: replace value in df 
Python :: python insert on a specific line from file 
Python :: loop through list of tuples python 
Python :: construct contingency table from pandas 
Python :: random picker in python 
Python :: two sum python 
Python :: changing the current working directory in python 
Python :: python append a file and read 
Python :: python turn off printing 
Python :: how to create window in tkinter 
Python :: mouse bottom in pygame 
Python :: pd df drop columns 
Python :: fibonacci number in python 
Python :: regex findall 
Python :: convert dict to string python 
Python :: .encode python 
Python :: pip install for python 2 and python3 
Python :: Adjusting Subplot Margins in Matplotlib 
Python :: pandas dataframe read string as date 
Python :: time addition in python 
Python :: # time delay in python script 
Python :: python get average of list 
Python :: two for loops in list comprehension 
Python :: elon musk wikipedia 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =