IntersectI
IntersectI
IntersectI[ list1, list2, ... ] returns the indices of the elements of the first list that also occur in all other lists.
Usages
IntersectI[ list1, list2, ... ]
IntersectI[ list1, list2, ... ] returns the positions (starting at 1) of the elements of list1 that also occur in list2, list3, .... These are the positions of the elements that Intersect would keep. Use it when you need to know where the common elements are.
| Example | in | out |
|---|---|---|
a (position 1) and b (position 2) occur in both lists. |
IntersectI[ {a,b,g}, {a,b,c,d,e,a} ] |
{1, 2} |
Both a's are kept, because the second list also contains a twice. |
IntersectI[ {a,b,g,a}, {a,c,a} ] |
{1, 4} |
Only the first a is kept, because the second list contains a once. |
IntersectI[ {a,b,g,a}, {a,c} ] |
{1} |
Three lists: only a occurs in all of them. |
IntersectI[ {a,b,g,a}, {a,b,c,d,e,a}, {g,d,f,a} ] |
{1} |
Details
- Duplicates are counted separately: each element of the other lists can match only one element of
list1, working from left to right. - Equal elements: elements match if they are the same expression, regardless of the order of terms or factors. Numbers must have the same form:
IntersectI[ {2.4, 3}, {12/5, 3} ]returns{2}. - Empty lists: if any of the other lists is empty, the result is
{}.
| Invalid input | Result |
|---|---|
IntersectI[ {a,b}, b ] |
Left unevaluated: the result is IntersectI[ {a,b}, b ] itself. All arguments must be lists. |
Warning
- With a single list,
IntersectI[ {a,b} ]returns the list{a, b}itself, not a list of indices. Always give at least two lists. IntersectIcompares numbers with a limited precision differently fromIntersect. For example,Intersectconsiders1+PrecisionConstant[3.14,2]and1+3.1415equal, butIntersectIdoes not.
See also: Intersect, DifferenceI, FindI