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
+ 0 comments the first option(better):
print(re.sub(r'\b\W+\b', ' ', ''.join([''.join([x[i] for x in matrix]) for i in range(m)])))
the second option:
s = ''.join([''.join([mat[i] for mat in matrix]) for i in range(m)]) t = max([''] + re.findall(r'[0-9a-zA-Z].*[0-9a-zA-Z]', s)) tn = re.sub(' +', ' ', re.sub(r'[!@#$%&]', ' ', t)) print(s.replace(t, tn))
+ 0 comments #!/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) string = "" for i in range(m): for j in range(n): string += (matrix[j][i]) string = re.sub(r"\b\W+\b", " ", string) #very clean string #string = re.sub(r"[\W]", " ", string) #string = re.sub(r" +", " ", string) #but not for this task #one bad testcase: #string = re.sub(r"(\w*?)\W+(\w\W*?)", r"\1 \2", string) print(string)
+ 0 comments Solution I made
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 i in range(m)] for _ in range(n): matrix_item = input() for j in range(len(matrix_item)): matrix[j] = matrix[j]+str(matrix_item[j]) encoded = "".join(matrix) print(re.sub(r'(?<=\w)[^\w]+(?=\w)', ' ', encoded))
+ 0 comments Solution I made
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 i in range(m)]
for _ in range(n): matrix_item = input() for j in range(len(matrix_item)): matrix[j] = matrix[j]+str(matrix_item[j])
encoded = "".join(matrix) print(re.sub(r'(?<=\w)[^\w]+(?=\w)', ' ', encoded))
+ 0 comments Neo could have gotten a cleaner line. But Neo decided to remove characters only between words...
#!/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) string = "" for i in range(m): for j in range(n): string += (matrix[j][i]) string = re.sub(r"\b\W+\b", " ", string) #very clean string #string = re.sub(r"[\W]", " ", string) #string = re.sub(r" +", " ", string) #but not for this task #one bad testcase: #string = re.sub(r"(\w*?)\W+(\w\W*?)", r"\1 \2", string) print(string)
Load more conversations
Sort 451 Discussions, By:
Please Login in order to post a comment