Haskell:如何将元素列表拆分为几个列表[a]-> [[a]]

时间:2019-03-28 16:31:26

标签: list haskell split

我有一个给定的Int(例如3)和一个元素列表。

我想将这些元素按3个列表排序(取决于给定的int)。

例如:3 [a,b,c,d,e,f,g] -> [[a,d,g],[b,e],[c,f]]

我只知道函数:

chunksOf 3 ['a'..'z']
["abc","def","ghi","jkl","mno","pqr","stu","vwx","yz"]

提前谢谢

1 个答案:

答案 0 :(得分:3)

您要transpose

transpose ["abc", "def", "g"]

给予

["adg","be","cf"]

您可以将其组合

transpose $ chunksOf 3 "abcdefg"