If i had three lists such as
a = [1, 2, 3]
b = [4, 5, 6]
c = [7, 8, 9]
And wanted to print it like this
1 4 7
2 5 8
3 6 9
How would i do that?
The hard part of this is transposing the array. But that's easy, with zip
:
a = [1, 2, 3]
b = [4, 5, 6]
c = [7, 8, 9]
t = zip(a, b, c)
Now you just print it out:
print('\n'.join(' '.join(map(str, row)) for row in t))
This should do it:
'\n'.join(' '.join(map(str,tup)) for tup in zip(a,b,c))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With