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.
Here is a really simple but hopefully readable solution:
#!/bin/python3
import re
n, m = map(int, input().split())
matrix = [ input() for _ in range(n) ]
# a very Pythonic way to transpose and flatten a list of iterables - barely readable but you know what it's doing
transpose = ''.join([c for ls in zip(*matrix) for c in ls])
# Lookaheads and Lookbehinds let us use a simple 'sub' to replace every sandwiched cluster of symbols.
print(re.sub(r"(?<=\w)[!@#$%& ]+(?=\w)", " ", transpose))
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Matrix Script
You are viewing a single comment's thread. Return to all comments →
Here is a really simple but hopefully readable solution: