0

I have a list of lists like [[a,c,e],[b,d,f]] and I was wondering how to print out every value from the lists, one at a time from each list.

The order I want when I print is abcdef.

I've been thinking about this for a while but I can't seem to figure it out.

1
  • 7
    You could "concat" the list to get [a,c,e,b,d,f], and then print it. Ah, but that's the wrong order. It's printing the row-major order of your matrix, but you seek the column major order. If only there were a way to transpose a matrix before you concat... Commented May 11, 2015 at 3:25

2 Answers 2

1

How's the following

concat $ transpose [[1,2,3],[4,5,6]]

returns

[1,4,2,5,3,6]

mapM_ (putStr . show) [1,4,3,5,3,6]
Sign up to request clarification or add additional context in comments.

Comments

0
combine :: [a] -> [a] -> [a]
combine [] ys = ys
combine (x:xs) ys = x:combine ys xs

main :: IO ()
main = do
    print (combine [1,3,5] [2,4,6])
    return ()

outputs: [1,2,3,4,5,6]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.