Intersection
Syntax
$set1.intersection($set2)
Description
Calculates the intersection of the sets set1
and set2
.
Parameter
Name | Type | Description | Mandatory | Default |
---|---|---|---|---|
set1 | Set | A set for which it is to be checked whether and which elements are also contained in set2 . |
yes | |
set2 | Set | A set for which to check whether and which elements are also contained in set1 . |
yes |
Return value
Type: Set
A set containing all elements that are included in both set1
, and set2
.
Examples
Intersection
list(1, 2, 3).intersection(list(2, 3))
Output: A set with the elements [2, 3].
Intersection for duplicate values
list(1, 2, 2, 3).intersection(list(2, 2, 3))
Output: A set with the elements [2, 3].
Duplicate values do not appear twice in the result.
No intersection
list(1, 2, 3).intersection(list(5, 6))
Output: An empty set