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.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Python
  3. Regex and Parsing
  4. Matrix Script
  5. Discussions

Matrix Script

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 451 Discussions, By:

recency

Please Login in order to post a comment

  • jarek108
    41 minutes ago+ 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|
    Permalink
  • keshabkjha
    23 hours ago+ 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|
    Permalink
  • haiderjutt95
    2 days ago+ 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|
    Permalink
  • haiderjutt95
    2 days ago+ 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|
    Permalink
  • belov
    1 week ago+ 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)
    
    0|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy