cancel
Showing results forΒ
Did you mean:Β

## getting multiple occurrences of an item in a list as a list

Does anyone knows what is the function to get multiple of occurrences of an item in a list as list of indexes.

example:

with fun(iList,"item") as occurencesOfItem

unwind occurencesOfItems

....

1 ACCEPTED SOLUTION
Ninja

I am not sure I understand your requirement. I think you want a method of deriving the indexes of a given item from a list of elements. If so, the following demonstrates a solution for a list of integers. The result of executing the cypher is [2,4], which is index positions of each occurrence of '6'.

``````with [3, 4, 6, 2, 6, 3, 7] as x, 6 as item
return [i in range(0,size(x)-1) where x[i] = item] as indexes``````

Is this what you are looking for?

2 REPLIES 2
Ninja

I am not sure I understand your requirement. I think you want a method of deriving the indexes of a given item from a list of elements. If so, the following demonstrates a solution for a list of integers. The result of executing the cypher is [2,4], which is index positions of each occurrence of '6'.

``````with [3, 4, 6, 2, 6, 3, 7] as x, 6 as item
return [i in range(0,size(x)-1) where x[i] = item] as indexes``````

Is this what you are looking for?