Computer Science, asked by aary8083, 2 months ago

Nandini has a complex matrix script. The matrix script is a N X M grid of strings. It consists of alphanumeric characters and symbols (!,@,#,$,%,&). To decode the script, Nandini needs to read each column and select only the alphanumeric characters and connect them. She reads the column from top to bottom and starts reading from the leftmost column. If there are symbols in the decoded script, then Nandini removes them for better readability. Alphanumeric characters consist of: [A-Z, a-z, and 0-9].

Input Format

The first line contains space-separated integers N (rows) and M (columns) respectively.
The next N lines contain the row elements of the matrix script separated by space.

Output Format

Print the decoded matrix script.
Sample Input:
7 3
T s i
h % x
i # $
s M #
$ a &
# t %
i r !
Output:
ThisisMatrix​

Answers

Answered by maheedharreddy08
6

Answer:

import re

N,M=map(int,input().split())

l=list()

for i in range(N):

   l.append(input())  

l=list(zip(*l))

s=''

for i in l:

   s=s+''.join(i)

s=''

for i in l:

   s=s+''.join(i)

s=re.sub(r'\b[^a-zA-Z0-9]+\b',r'',s)

print(s)

Explanation:

Similar questions