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
|
559 Discussions
|
Please Login in order to post a comment
I did this a liltte differently. First difference being that I made an empty 2D-list of the matrix from the given size. Then I place each character in the correct position using math x+(n*y). And finally join with a regex subsutition. Also,
\w
& \W are great replacements for all of that text the rest of you have.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)
st="" for i in range(m): for j in range(n): st += matrix[j][i] st = re.sub(r'(?<=\w)([$#%! ]+)(?=\w)'," ",st) print(st)
import re
n, m = input().strip().split()
tt = []
ss = []
for _ in range(int(n)):
res = "".join(tt)
for nm in range(int(m)):
fin = re.sub(r"[!,@,#,$,%,&]+(?=([A-z0-9]))", " ", "".join(ss)) print(fin)
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[:m])
text = ''.join(matrix) assigned_text=[]
for i in range(m): for j in range(i,len(text),m): assigned_text.append(text[j])
print(re.sub(r'(?<=[0-9a-zA-Z])[!,@,#,$,%,&,\s]+(?=[0-9a-zA-Z])',' ',''.join(assigned_text)))