Macaulay2 » Documentation
Packages » Macaulay2Doc :: positions
next | previous | forward | backward | up | index | toc

positions -- which elements of a list satisfy a condition

Synopsis

Description

The indices are listed in ascending order. If no element satisfies the condition, an empty list is returned.

i1 : positions((10,20,43,105,6,93), odd)

o1 = {2, 3, 5}

o1 : List
i2 : positions((10,20,43,105,6,93), i -> i<0)

o2 = {}

o2 : List
i3 : positions(100..110, isPrime)

o3 = {1, 3, 7, 9}

o3 : List

To find the first or last index of an element satisfying the condition, see position. To return the elements, rather than their indices, see select. The function number counts the number of elements satisfying the condition.

i4 : position((10,20,43,105,6), odd)

o4 = 2
i5 : position((10,20,43,105,6), odd, Reverse => true)

o5 = 3
i6 : select((10,20,43,105,6), odd)

o6 = (43, 105)

o6 : Sequence
i7 : number((10,20,43,105,6), odd)

o7 = 2

See also

Ways to use positions :

For the programmer

The object positions is a method function.