Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

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
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #intersection #lists
ADD COMMENT
Topic
Name
3+9 =