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 :: count occurrences of character in string python using dictionary 
Python :: python seaborn color map 
Python :: get weekday from date python 
Python :: python do something while waiting for input 
Python :: paradigm meaning in python 
Python :: python split list 
Python :: correlation for specific columns 
Python :: how to make a terminal in python 
Python :: scikit learn train test split 
Python :: streamlit install 
Python :: Matplotlib inside Jupyter | Jupyter generate graphs. 
Python :: seaborn.distplot() 
Python :: finding the maximum value in a list python 
Python :: python turtle fill 
Python :: python save button 
Python :: import turtle as t 
Python :: how to download packages using pip 
Python :: if-else 
Python :: drop na pandas 
Python :: python opencv measure distance two shapes 
Python :: get the name of all files in a computer in python 
Python :: how to check if value is in list python 
Python :: How to Adjust Title Position in Matplotlib 
Python :: beautifulsoup import 
Python :: res.send is not a function 
Python :: parallel loops in python 
Python :: pandas reset index from 0 
Python :: python3 check if object has attribute 
Python :: seaborn distplot 
Python :: how to create a virtual environment in python 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =