• + 1 comment

    Why am i getting a wrong answer in this? However my output matches with the expected output.

    #!/bin/python3
    
    import math
    import os
    import random
    import re
    import sys
    
    
    
    
    first_multiple_input = input().rstrip().split()
    
    n = int(first_multiple_input[0])
    
    m = int(first_multiple_input[1])
    
    matrix = []
    
    for _ in range(n):
        matrix_item = input()
        matrix.append(matrix_item)
    transposed_matrix = [''.join(row[i] for row in matrix) for i in range(m)]
    result = ""
    flag=False
    Edge_case = ""
    for rows in transposed_matrix:
        for columns in rows:
            if 'A'<=columns<='Z' or 'a'<=columns<='z' or '0'<=columns<='9':
                if(flag):
                    result+= " "
                result+=columns
                Edge_case=""
                flag=False
                
            else:
                Edge_case+=columns
                flag = True
                continue
    if len(Edge_case)>0:
        result+=Edge_case
    print(result)