如何在列表中找到元素的索引? [英] How to find the index of an element in a list?
本文介绍了如何在列表中找到元素的索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在列表中提供一个元素,我可以使用哪个函数来查找其索引?
Giving an element in a list, which function can I use to find its index?
例如,我想在列表 [1、2、3、4]
中找到3的索引.
For instance, I want to find the index of 3 in the list [1, 2, 3, 4]
.
Haskell中可以使用哪些功能?
Which function exists in Haskell that I can use for this?
推荐答案
在这里看看:
即使用 Data.List
中的 elemIndex
:
elemIndex :: Eq a => a -> [a] -> Maybe Int
这篇关于如何在列表中找到元素的索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文