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 :: os.mkdir exceptions 
Python :: remove newline and space characters from start and end of string python 
Python :: list from comma separated string python 
Python :: bitcoin wallet python 
Python :: sort an array python 
Python :: python sort array of dictionary by value 
Python :: django pandas queryset 
Python :: python face recognition 
Python :: python pandas convert series to percent 
Python :: if else one line python 
Python :: remove all rows with at least one zero pandas 
Python :: round off float to 2 decimal places in python 
Python :: asymmetric encryption python 
Python :: how to run terminal commands in python 
Python :: python generator 
Python :: plot pil image colab 
Python :: mkvirtualenv environment python 3 
Python :: create a dictionary from a list python 
Python :: displaying cv2.imshow on specific window position 
Python :: ValueError: With n_samples=0, test_size=0.2 and train_size=None, the resulting train set will be empty. Adjust any of the aforementioned parameters. 
Python :: python getters and setters 
Python :: startapp django 
Python :: pyqt5 image center 
Python :: can is slice list with list of indices python 
Python :: create a timestamp python 
Python :: custom position for axis matplotlib 
Python :: read file csv in python 
Python :: django environment variables 
Python :: random 2 n program in python 
Python :: assign a same value to 2 variables at once python 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =