transpose of a list of lists

后端 未结 2 495
-上瘾入骨i
-上瘾入骨i 2020-12-11 17:33

I\'m trying to make a recursive function to get the transpose of a list of lists, n x p to p x n. But i\'m unable to do so. I\'ve been able to make

2条回答
  •  生来不讨喜
    2020-12-11 18:08

    let rec transpose list = match list with
    | []             -> []
    | []   :: xss    -> transpose xss
    | (x::xs) :: xss ->
        (x :: List.map List.hd xss) :: transpose (xs :: List.map List.tl xss)
    

提交回复
热议问题