过滤列表中的位置,Haskell [英] Filter positions in a list, Haskell
本文介绍了过滤列表中的位置,Haskell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要打印奇数索引的元素.当前正在打印索引.
I need to print the elements of odd index. Currently is printing index.
我不明白如何打印此索引的元素?
I don't understand how I can print elements of this index?
f :: [Int] -> [Int]
f lst = filter odd [0..length lst]
-- I can't edit this part
main = do
inputdata <- getContents
mapM_ (putStrLn. show). f. map read. lines $ inputdata
推荐答案
如果您想徒步"进行此操作:
If you want to do this "on foot":
odds [] = []
odds [x] = []
odds (e1:e2:xs) = e2 : odds xs
这篇关于过滤列表中的位置,Haskell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文