We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Python
- Regex and Parsing
- Matrix Script
- Discussions
Matrix Script
Matrix Script
Sort by
recency
|
590 Discussions
|
Please Login in order to post a comment
I am confused about why this is not working. If anyone can help I'll apreceate.
Here is a really simple but hopefully readable solution:
!/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)
text = "" for col in range(len(matrix[0])): for row in matrix: text += row[col]
result = re.sub(r'(?<=\w)[\W]+(?=\w)', ' ', text)
print(result)
result = re.sub(r'(?<=\w)[\W]+(?=\w)', ' ', text)
print(result)