0

Here is a Haskell list:

[[1],[3,5],[],[1,9],[3,5],[9,7],[1,9]]

I want to find the exact index of its elements. I tried to use elemIndex but it doesn't give the correct index when I try to find duplicated element like [3,5] and [1,9].

3
  • when you look for a duplicated element, do you want the first index, the last index, or all indices? Commented Dec 16, 2014 at 22:10
  • Do you mean you want to find all the locations of [3,5] - not jus the first? Commented Dec 16, 2014 at 22:10
  • Yes! all locations. For example for [3,5] the index will be [1,4] Commented Dec 16, 2014 at 22:12

1 Answer 1

1

Is this what you want?

> elemIndices  [3,5] [[1],[3,5],[],[1,9],[3,5],[9,7],[1,9]]
[1,4]
Sign up to request clarification or add additional context in comments.

1 Comment

How about if I want to associate it with it's index like [(0,[1]), (1,[3,5]), (2,[]), (3,[1,9]), (4,[3,5]), (5,[9,7]), (6,[1,9])]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.