You are viewing a single comment's thread. Return to all comments →
import re
n, m = map(int, input().split())
matrix = [input() for _ in range(n)]
decoded = ''.join([matrix[i][j] for j in range(m) for i in range(n)])
print(re.sub(r'(?<=[A-Za-z0-9])[^A-Za-z0-9]+(?=[A-Za-z0-9])', ' ', decoded))
Seems like cookies are disabled on this browser, please enable them to open this website
Matrix Script
You are viewing a single comment's thread. Return to all comments →
import re
Step 1: Input dimensions
n, m = map(int, input().split())
Step 2: Read the matrix
matrix = [input() for _ in range(n)]
Step 3: Transpose the matrix and build the decoded string
decoded = ''.join([matrix[i][j] for j in range(m) for i in range(n)])
Step 4: Use regex to replace symbols/spaces between alphanumerics with space
print(re.sub(r'(?<=[A-Za-z0-9])[^A-Za-z0-9]+(?=[A-Za-z0-9])', ' ', decoded))