Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

intersection of two lists python

>>> a = [1,2,3,4,5]
>>> b = [1,3,5,6]
>>> list(set(a) & set(b))
[1, 3, 5]
Comment

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

not intersection of two lists python

set(a) ^ set(b)
{2, 4, 6}
Comment

intersection of lists in python

import numpy as np
recent_coding_books =  np.intersect1d(recent_books,coding_books)
Comment

intersection of two lists python

# Python program to illustrate the intersection
# of two lists in most simple way
def intersection(lst1, lst2):
	lst3 = [value for value in lst1 if value in lst2]
	return lst3

# Driver Code
lst1 = [4, 9, 1, 17, 11, 26, 28, 54, 69]
lst2 = [9, 9, 74, 21, 45, 11, 63, 28, 26]
print(intersection(lst1, lst2))
Comment

python get the intersection of two lists

# intersection of two lists (lst1 & lst2)
In [1]: x = ["a", "b", "c", "d", "e"]

In [2]: y = ["f", "g", "h", "c", "d"]

In [3]: set(x).intersection(y)
Out[3]: {'c', 'd'}
# has_intersection = bool(set(x).intersection(y)) -> True
Comment

PREVIOUS NEXT
Code Example
Python :: python copy file to another directory 
Python :: convert text file into list 
Python :: python pil resize image 
Python :: get all the keys in a dictionary python 
Python :: auth proxy python 
Python :: log base 2 python 
Python :: python how much memory does a variable need 
Python :: how to extract data from website using beautifulsoup 
Python :: np array value count 
Python :: get local timezone python 
Python :: order by listview django 
Python :: pandas append dictionary to dataframe 
Python :: python print code 
Python :: how to send get request python 
Python :: django gmail smtp 
Python :: python time a funciton 
Python :: get all occurrence indices in list python 
Python :: age in days to age in years 
Python :: spark dataframe get unique values 
Python :: python -m pip install --upgrade 
Python :: insert picture into jupyter notebook 
Python :: how to return the derivative of a function in python 
Python :: bar chart with seaborn 
Python :: string module in python 
Python :: how to switch python version in ubuntu 
Python :: python year month day hour minute second 
Python :: python check if list contains elements of another list 
Python :: python process id 
Python :: how to rotate the x label for subplot 
Python :: python file extension 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =