3

This is my list:

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

I want it to print like this:

1 2 4
2 3 5
3 4 6

I have tried using:

for xs in numbs:
    print(" ".join(map(str, xs)))

But it prints this instead:

1 2 3
2 3 4
4 5 6
costaparas
  • 5,047
  • 11
  • 16
  • 26
wildling
  • 33
  • 4

1 Answers1

2

It looks like you are using python so you are looking for the built-in function zip():

zip(*numbs)
[(1, 2, 4), (2, 3, 5), (3, 4, 6)]

And formatted the way you asked for:

print("\n".join([ " ".join(map(str, l)) for l in zip(*numbs) ])) 
1 2 4
2 3 5
3 4 6
Allan Wind
  • 23,068
  • 5
  • 28
  • 38