Simon S Simon S - 3 months ago 9
Python Question

Print list of lists in Python in specific order

I have this list:

vshape = [['0','1','1'],['1','0','1'],['1','1','0'],['1','0','1'],['0','1','1']]


I need to print out every item in specific order -
one line of vshape[0][0], vshape[1][0], vshape[2][0], vshape[3][0], and vshape[4][0];
followed by line of vshape[0][1], vshape[1][1] ans so on...

Output should look like ('0's creating a V-shape):

01110
10101
11011

Answer

Use zip:

for r in zip(*vshape):
    print(''.join(r))

# 01110
# 10101
# 11011
Comments