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
|
550 Discussions
|
Please Login in order to post a comment
!/bin/python3
import re
Read dimensions of the matrix
first_multiple_input = input().rstrip().split() rows = int(first_multiple_input[0]) cols = int(first_multiple_input[1])
Initialize matrix
matrix = []
Read the matrix rows
for _ in range(rows): matrix.append(input())
Decode the matrix script
decoded_script = [] for col in range(cols): # Extract characters from each column column_chars = ''.join(matrix[row][col] for row in range(rows)) decoded_script.append(column_chars)
Join the characters and replace non-alphanumeric characters with space
decoded_script_str = ''.join(decoded_script) decoded_script_str = re.sub(r'(?<=[a-zA-Z0-9])[^a-zA-Z0-9]+(?=[a-zA-Z0-9])', ' ', decoded_script_str)
Print the decoded script
print(decoded_script_str)
Example using zip to transpose the matrix
All my test cases are passing but I am getting a score of 75. Does anybody know why?