Skip to main content

Multidimensional list in python print as matrix

 Two Dimensional List in Python 

Print the two-dimensional list mult_table by row and column using Nested loops

Sample Output with input: 1 2 3, 2 4 6, 3 6 9

1 | 2 | 3

2 | 4 | 6

3 | 6 | 9


 user_input = input()

 lines = user_input.split(',')
 mult_table = [[int(num) for num in line.split()] for line in lines]
 for lst in mult_table:
     for i in range(len(lst)):
         print(lst[i], end='')
         if i != len(lst)-1:
             print(' | ', end='')
  print()

Hope this is helpful. Write back to me in case you need help with your python task. I generally reply back within 24 hours. You can connect with me on Whatsapp also: +918602715108

Comments