Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python find intersection of two lists

# 3 Approaches to find intersect of two lists:
# set two lists:
a = [1,2,3,4,5,6,7,8]
b = [8,7,4,3,100,200]
# the intersect c should be [3,4,7,8]
# Method 1:
c = list(set(a) & set(b))
print(c)
# Method 2:
c = list(filter(set(a).__contains__, b))
print(c)
# Method 3:
c = list(set(a).intersection(b))
Comment

intersection of two lists using set method

# Python program to illustrate the intersection
# of two lists using set() method
def intersection(lst1, lst2):
    return list(set(lst1) & set(lst2))
 
# Driver Code
lst1 = [15, 9, 10, 56, 23, 78, 5, 4, 9]
lst2 = [9, 4, 5, 36, 47, 26, 10, 45, 87]
print(intersection(lst1, lst2))
Comment

intersection of list of sets

u = set.intersection(*setlist)
Comment

PREVIOUS NEXT
Code Example
Python :: how to do merge sort in python 
Python :: pandas excelfile 
Python :: pdf to excel conversion using python 
Python :: format timedelta python 
Python :: import pycocotools._mask as _mask error Expected 80, got 88 
Python :: change a color on touch roblox 
Python :: python select file in folder given extension 
Python :: where to put capybara default wait time 
Python :: for loop to select rows in pandas 
Python :: feature importance plot using lasso regression 
Python :: python remove (string) 
Python :: python convert xml to dictionary 
Python :: mnist 
Python :: python cant find keras utils to_categorical 
Python :: python get object parameters 
Python :: colorbar with hist2d 
Python :: python remove last part of string 
Python :: how to check system has internet using python 
Python :: how to find number of categories in python 
Python :: kivy stuck in fullscreen in jupyter notebook macbook 
Python :: flask or django 
Python :: get last save id django model 
Python :: How to find the most similar word in a list in python 
Python :: python socket github 
Python :: sum of digits in python 
Python :: how to redirect where requests library downloads file python 
Python :: get every second elemnt of array matlab 
Python :: remove SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame 
Python :: calculate the R^2 for X and Y python 
Python :: python remove table widget numbers 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =