如何在Haskell列表中找到元素的索引 [英] How can I find the indexes of an element in Haskell list

查看:628
本文介绍了如何在Haskell列表中找到元素的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是Haskell列表:

Here is a Haskell list:

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

我想找到其元素的确切索引.我尝试使用elemIndex,但是当我尝试查找诸如[3,5][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].

推荐答案

这是您想要的吗?

> elemIndices  [3,5] [[1],[3,5],[],[1,9],[3,5],[9,7],[1,9]]
[1,4]

这篇关于如何在Haskell列表中找到元素的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆