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

Given two arrays, find their intersection.

Examples:

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(arr1,arr2) ` |

*chevron_right*

*filter_none*

Output:

Intersection : [3, 5]

Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: **DSA Self Paced**. Become industry ready at a student-friendly price.

## Recommended Posts:

- Map function and Lambda expression in Python to replace characters
- Lambda and filter in Python Examples
- Python | Find the Number Occurring Odd Number of Times using Lambda expression and reduce function
- Python lambda (Anonymous Functions) | filter, map, reduce
- Lambda expression in Python to rearrange positive and negative numbers
- Python | Find common elements in three sorted arrays by dictionary intersection
- Nested Lambda Function in Python
- Ways to sort list of dictionaries by values in Python - Using lambda function
- Intersection() function Python
- Union and Intersection of two sorted arrays
- Find Union and Intersection of two unsorted arrays
- Python lambda
- Overuse of lambda expressions in Python
- Python | sympy.Lambda() method
- Python Lambda with underscore as an argument
- Difference between List comprehension and Lambda in Python
- Python Program to Sort the list according to the column using lambda
- Python | Find fibonacci series upto n using lambda
- Spatial Filters - Averaging filter and Median filter in Image Processing
- Python | Records Intersection

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. 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.