我如何找到Haskell列表中元素的索引 [英] How can I find the index of an element in Haskell list
本文介绍了我如何找到Haskell列表中元素的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
[[1],[3,5],[],[1, 9],[3,5],[9,7],[1,9]]
我想找到它的元素的确切索引。我尝试使用 elemIndex
,但是当我尝试查找重复元素像 [3,5] $ c时,它没有给出正确的索引$ c>和
[1,9]
。
解决方案
你想要什么?
> elemIndices [3,5] [[1],[3,5],[],[1,9],[3,5],[9,7],[1,9]]
[1 ,4]
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]
.
解决方案
Is this what you want?
> elemIndices [3,5] [[1],[3,5],[],[1,9],[3,5],[9,7],[1,9]]
[1,4]
这篇关于我如何找到Haskell列表中元素的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文