Reputation: 33
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
Upvotes: 3
Views: 57
Reputation:
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
Upvotes: 2