intersect

A Python module used for interacting with collections of objects using LINQ syntax


intersect

intersect(enumerable, key)

Returns an Enumerable that is the result of an intersection between two Enumerable instance based on the value of the key given. This is not an executing function.

Parameters

enumerable : an Enumerable instance to intersect with.
key : lambda function used as the key selector for both sets

Returns

An Enumerable object that contains the common elements between the two Enumerables based on the given key.

Examples


from py_linq import Enumerable

marks1 = Enumerable([{ 'course' : 'Chemistry', 'mark': 90 }, {'course': 'Biology', 'mark': 85 }])
marks2 = Enumerable([{ 'course': 'Chemistry', 'mark': 65}, {'course': 'Computer Science', 'mark': 96 }])
common_courses = marks1.intersect(marks2, lambda c: c['course'])