I’ve got a 2D list in Python like this:
[['Something', 'Something else', 'Another thing'],
['Other things', 'More data', 'Element'],
['Stuff', 'data', 'etc']]
I want it to be printed out like this:
Something Something else Another thing
Other things More data Element
Stuff data etc
Here, first the list gets transformed with
zip(*l): each of the sub lists gets passed as an own argument tozip(). The result is a list which combines the n-th entries of each old list, so you get[['Something', 'Other things', 'Stuff'], ['Something else', 'More data', 'data'], ...].Then the entries whose lengths are to be matched are in the same
column. In each of thesecolumns the strings areljust()ed to the greatest length in the group.After that, the new list with the adjusted lengths is transformed again – in the same way as above – and the components joined with a
" "in-between.The resulting 1D list is then printed entry by entry.