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 :: How to Loop Through Tuples using while loop in python 
Python :: short hand function pytho 
Python :: list of object in python 
Python :: how to track exact location of a phone number in python 
Python :: How to subtract all the numbers in a list from the first number? 
Python :: The float type in Python3 can represent decimal 0.1 without error. 
Python :: python if modulo 
Python :: palindrome program in python 
Python :: immutabledict working 
Python :: flask-sqlalchemy inheritance 
Python :: design patterns in python free download 
Python :: Python | Set 3 (Strings, Lists, Tuples, Iterations) 
Python :: how to print tic tac toe border on terminal in python 
Python :: Python script to do something at the same time every day 
Python :: first flask api 
Python :: Boolean comparison w/out if statements 
Python :: calculate values in a certain percentile pandas 
Python :: python list chunks using yield 
Python :: cgi in python; get() method 
Python :: india states django choices 
Python :: arabic text recognition from pdf using python 
Python :: python bill 
Python :: how to create a cubic function in python 3 
Python :: how to write a program that interacts with the terminal 
Python :: Seaborn boxplots shifted incorrectly along x-axis 
Python :: inspect rows in dictionary pthon 
Python :: Reading from a file way02 
Python :: Python Iterating Through a Tuple 
Python :: numpy subtraction operation using numpy functions 
Python :: lists example in python 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =