haskell(24)

elemIndex和elemIndices在列表中查找元素,elemIndex返回找到的第一个元素的位置,而elemIndices返回找到的所有元素的位置。 

Prelude Data.List> 66 `elemIndex` [1,23,66,2,6,90]

Just 2

Prelude Data.List> 23 `elemIndex` [1,23,66,23,6,90]

Just 1

Prelude Data.List> 23 `elemIndices` [1,23,66,23,6,90]

[1,3]

findIndex和findIndices在列表中查找符合函数要求的元素,findIndex返回第一个元素,而findIndices返回所有满足要求的元素。

Prelude Data.List> findIndex  (==23) [1,23,66,23,6,90]

Just 1

Prelude Data.List> findIndices  (==23) [1,23,66,23,6,90]

[1,3] 

zip4类似于zip,但接收4个列表做为参数。

*Main Data.List> zip4 [1,2,3] [4,5,6] [7,8,9] [10,11,12]

[(1,4,7,10),(2,5,8,11),(3,6,9,12)]

*Main Data.List> 

zip3同上,

*Main Data.List> zip3 [1,2,3] [4,5,6] [7,8,9] 

[(1,4,7),(2,5,8),(3,6,9)]

zipWith3zipWith4zip3zip4类似,但是将列表中元素分别参与函数运算。

*Main Data.List> zipWith3 (\x y z->x^2+y^2+z^2) [1,2,3] [4,5,6] [7,8,9] 

[66,93,126]

*Main Data.List> zipWith4 (\x y z b->x^2+y^2+z^2+b) [1,2,3] [4,5,6] [7,8,9] [10,11,12] 

[76,104,138]

*Main Data.List>

本博客所有内容是原创,未经书面许可,严禁任何形式的转载。

http://blog.csdn.net/u010255642



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值