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?
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))
With list comprehension generator expression, without the map function:
'\n'.join(' '.join(str(y) for y in x) for x in zip(a,b,c))