You want to rearrange the list of lists by making row columns and row columns into rows:
grid = [['.', '.', '.', '.', '.', '.'], ['.', '0', '0', '.', '.', '.'], ['0', '0', '0', '0', '.', '.'], ['0', '0', '0', '0', '0', '.'], ['.', '0', '0', '0', '0', '0'], ['0', '0', '0', '0', '0', '.'], ['0', '0', '0', '0', '.', '.'], ['.', '0', '0', '.', '.', '.'], ['.', '.', '.', '.', '.', '.']] print("\n".join(map("".join,zip(*grid))))
Of:
..00.00.. .0000000. .0000000. ..00000.. ...000... ....0....
Or using a slightly different syntax with print_function , we can unzip with * and specify a separator with sep .:
from __future__ import print_function print(*map("".join,zip(*grid)),sep="\n")
Using python2, if you don't want to create proxy lists, you can use itertools so that it becomes the following:
from __future__ import print_function from itertools import imap, izip print(*imap("".join,izip(*grid)),sep="\n")
For completeness and to show you what your transposed list looks like:
from pprint import pprint as pp pp(list(zip(*grid))) [('.', '.', '0', '0', '.', '0', '0', '.', '.'), ('.', '0', '0', '0', '0', '0', '0', '0', '.'), ('.', '0', '0', '0', '0', '0', '0', '0', '.'), ('.', '.', '0', '0', '0', '0', '0', '.', '.'), ('.', '.', '.', '0', '0', '0', '.', '.', '.'), ('.', '.', '.', '.', '0', '.', '.', '.', '.')]
What if you really need lists instead of tuples, you could map back to the list:
pp(list(map(list,zip(*grid)))) [['.', '.', '0', '0', '.', '0', '0', '.', '.'], ['.', '0', '0', '0', '0', '0', '0', '0', '.'], ['.', '0', '0', '0', '0', '0', '0', '0', '.'], ['.', '.', '0', '0', '0', '0', '0', '.', '.'], ['.', '.', '.', '0', '0', '0', '.', '.', '.'], ['.', '.', '.', '.', '0', '.', '.', '.', '.']]