Python | Print the list vertically

Method # 1: Using the naive method
The naive method can be used to print the list vertically. using loops sequentially and printing each element of the index of each list will help us solve this problem.

# Python3 demo code
# Vertical print list
# using the naive method

 
# initializing list

test_list = [[ 1 , 4 , 5 ], [ 4 , 6 , 8 ], [ 8  , 3 , 10 ]]

 
# print of the original list

print ( "The original list is: " + str (test_list))

 
# using the naive method
# print the list vertically

for i in range ( len (test_list)):

for x in test_list:

  print (x [i], end = `` )

print ()

Output:

 The original list is: [[1, 4, 5], [4, 6, 8], [8, 3 , 10]] 1 4 8 4 6 3 5 8 10 

Method # 2: Using zip()
Using zip function, we map the items with the corresponding index to each other and then print each one. This performs the task of vertical printing.

# Python3 demo code
# Vertical print list
# using zip ()

 
# initializing list

test_list = [[ 1 , 4 , 5 ], [ 4 , 6 , 8 ], [ 8 , 3 , 10 ]]

 
# printing the original list

print ( "The original list is:" + str (test_list))

 
# using zip ()
# print the list vertically

for x, y, z in zip ( * test_list):

print (x, y, z)

Output:

 The original list is: [[1, 4, 5], [4, 6, 8], [8, 3, 10]] 1 4 8 4 6 3 5 8 10