In Python How Do You Print Just The Values of The Two-dimensional List without The Quotes, Commas or Brackets?

Problem scenario
In Python your program has a two-dimensional list. It prints out like this:

[' ', 'X', ' ', ' ', ' ']
[' ', 'X', 'X', ' ', ' ']
[' ', 'X', 'X', 'X', ' ']
[' ', 'X', 'X', 'X', 'X']

You want it to print out like this:

 X 
 XX  
 XXX 
 XXXX

Solution
Assuming that there are n rows of your matrix (aka two-dimensional array), you can print out each row without quotes, commas or brackets if you iterate through the rows like this:

for x in range(0, n):
  str_a = ''.join(map(str, newlist[x]))
  print(str_a)

# Where newlist is the two-dimensional list you want to print

Leave a comment

Your email address will not be published. Required fields are marked *