• + 0 comments
    import re
    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)
    s = ''.join(matrix[y][x] for x in range(m) for y in range(n))
    p = r'(?<=[a-zA-Z0-9])[!@#$%&\s]+(?=[a-zA-Z0-9])'
    print(re.sub(p, ' ', s))