• + 1 comment
    import re
    
    def solve(matrix, n, m):
        string = ""
        # Here I use zip which transposes the matrix; that means it converts rows into columns
        # You can also use numpy
        # Using nested loops is not ideal in Python, so zip is used to avoid that
        matrix_T = list(zip(*matrix))
      
        for i in matrix_T:
            string += "".join(list(i))
        
        clear = re.sub(r'(?<=[a-zA-Z0-9_])[!@#$%&" "]+(?=[a-zA-Z0-9_])', ' ', string)
        
        print(clear)