Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python set intersection

both = {'a', 'A', 'b', 'B'}
some = {'a', 'b', 'c'}
result1 = both & some
# result: {'a', 'b'}
result2 = both.intersection(some)

print(result1 == result2)
# True
Comment

intersection() Function of sets in python

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

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

# Output:
# {3, 4}
Comment

How to Get the Intersection of Sets in Python

firstSet = {2, 3, 4, 5}

secondSet = {1, 3, 5, 7}

print(firstSet & secondSet)
# {3, 5}
Comment

Set .intersection() operation solution in python3

# Enter your code here. Read input from STDIN. Print output to STDOUT
num1, st1, num2, st2 = (set(input().split()) for i in range(4))
print(len(st1.intersection(st2)))
Comment

PREVIOUS NEXT
Code Example
Python :: python get volume free space 
Python :: pandas shift column down 
Python :: how to practise python 
Python :: measure execution time in jupyter notebook 
Python :: Django group by date from datetime field 
Python :: python join with int 
Python :: pandas read csv skip first line 
Python :: concatenate data vertically python 
Python :: cv2.threshold binary 
Python :: combine two dictionary adding values for common keys 
Python :: python choose sample from list with replacement 
Python :: python argparse type date 
Python :: Scaling Operation in SkLearn 
Python :: append one row to pandas dataframe 
Python :: df.select_dtypes 
Python :: specify the number of decimals in a dataframe 
Python :: pandas delete spaces 
Python :: set form field disabled django 
Python :: orderd set in python 
Python :: how to count the number of files in a directory using python 
Python :: console.log() python 
Python :: check if date is valid python 
Python :: read specific rows from csv in python 
Python :: python glob all files in directory recursively 
Python :: tkinter yes no dialogue box 
Python :: convert index of a pandas dataframe into a column 
Python :: radix sort python 
Python :: get sum from x to y in python 
Python :: import error in same directory python 
Python :: Read text file line by line using the readline() function 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =