select_index()
Select one or more items from a list and return the list of indexes of the items.
Synopsis
select_index(list-expression, test)
Description
The first argument specifies a list from which indices are to be selected, while the second argument specifies a true-false expression.
This action returns a list consisting of the positions of all items in the
first argument list for which the expression returns true
. The special
variable _
in the test refers to the list item being evaluated.
Parameters
list-expression
An expression that evaluates to the list to select from.
test
A true-false expression that us evaluated for each item in the list.
Returns
The function returns a list, which may be empty.
Examples
Select the indexes of the positive numbers from a list:
xlist = list(10, 0, -20, 0.5)
positives_index_list = select_index(x_list, _ > 0)
# positives_index_list = list(0, 3)