Intersection of two arrays in Python ( Lambda expression and filter function )

Given two arrays, find their intersection.


Input:  arr1[] = [1, 3, 4, 5, 7]
        arr2[] = [2, 3, 5, 6]
Output: Intersection : [3, 5]

We have existing solution for this problem please refer Intersection of two arrays link. We will solve this problem quickly in python using Lambda expression and filter() function.





# Function to find intersection of two arrays
def interSection(arr1,arr2):
     # filter(lambda x: x in arr1, arr2)  -->
     # filter element x from list arr2 where x
     # also lies in arr1
     result = list(filter(lambda x: x in arr1, arr2)) 
     print ("Intersection : ",result)
# Driver program
if __name__ == "__main__":
    arr1 = [1, 3, 4, 5, 7]
    arr2 = [2, 3, 5, 6]



Intersection : [3, 5]

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.