輸入工作列表時添加逗號哈斯克爾:</p> <p>我的代碼,使的輸出:打印整數
abc 2
am 1 2
and 2
do 2
i 1 2
like 2
not 2
spam 2
what 1
每個單詞與它出現的行號上市上。
問:你如何打印下面,你的行號之間獲得逗號,像這樣的語句:
abc 2
am 1,2
and 2
do 2
i 1,2
like 2
not 2
spam 2
what 1
下面是代碼我有需要採用這樣的格式
元組列表[([1, 2], "a"), ([1], "b"), ([1], "c"), ([2], "dd")]
,並打印到我的電流輸出,我上面列出:
combineInts listTuple = map f $ groupBy ((==) `on` fst) $ sortBy (compare `on` fst) $ map swap listTuple
where f [email protected](x:_) = (map snd xs, fst x)
printListTuples listTuple = unlines [ ys ++ " " ++ unwords (map show x) | (x, ys) <- listTuple ]
如果我能得到幫助,弄清楚如何在行號之間得到這些逗號,它會很有用,並且更具可讀性。
是你寫的代碼嗎? –