If I had three lists, for example
a = [1, 2, 3] b = [4, 5, 6] c = [7, 8, 9]
And I wanted to print it as follows
1 4 7 2 5 8 3 6 9
How can I do it?
The hard part of this is array transfer. But it is easy with zip :
zip
a = [1, 2, 3] b = [4, 5, 6] c = [7, 8, 9] t = zip(a, b, c)
Now you just print it:
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 a generator expression list without display function:
'\n'.join(' '.join(str(y) for y in x) for x in zip(a,b,c))
Source: https://habr.com/ru/post/1482026/More articles:How to decode a .lzo_deflat file? - pythonPointer view - cFlex: Help me understand the data. Binding to getters and setters. - flexOriginal reflection errors with has_many: via - ruby-on-railsstrtok does not drop newline - cDeleting a new line does not work after trying to check it - cRemoving all column elements in a two-dimensional array - arraysUpdating the end of a file in C ++ fstream - c ++Razor encodes quoted html attributes - asp.net-mvcWhat correct math fade with color? - c #All Articles