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.
# Method 1 Create String from Columns Using 2 loopsimportredimensions=list(map(int,input().split()))r=dimensions[0]c=dimensions[1]Matrix=[]for_inrange(r):Matrix.append(list(input()))S=""foriinrange(c):forjinrange(r):S+=Matrix[j][i]S=re.sub(r"(?<=\w)([!@#\$%\& ]+?)(?=\w)"," ",S)print(S)
# Method 2 Create String from Columns Using zip functionimportredimensions=list(map(int,input().split()))r=dimensions[0]c=dimensions[1]Matrix=[]for_inrange(r):Matrix.append(list(input()))S=""foriinlist(zip(*Matrix)):S+="".join(i)S=re.sub(r"(?<=\w)([!@#\$%\& ]+?)(?=\w)"," ",S)print(S)
# Method 3 Create String from Columns Using numpy but not working in compiler because of ModuleNotFoundErrorimportreimportnumpydimensions=list(map(int,input().split()))r=dimensions[0]c=dimensions[1]Matrix=[]for_inrange(r):Matrix.append(list(input()))S=""foriinnumpy.transpose(numpy.array(Matrix)):S+="".join(i)S=re.sub(r"(?<=\w)([!@#\$%\& ]+?)(?=\w)"," ",S)print(S)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Matrix Script
You are viewing a single comment's thread. Return to all comments →