Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I let the output be printed backwards?

So I wrote this code with the help of (https://stackoverflow.com/users/271641/marat)

def diagsUpRight(M):
    n = len(M)
    m = [['']*i + row + ['']*(n-i-1) for i, row in enumerate(M)]
    return [''.join(col) for col in zip(*m)]

and the output I get is this

['r', 'ax', 'wap', 'byqt', 'izbru', 'tceswn', 'hibxm', 'eovr', 'giw', 'to', 't']

Now, I want my code to print the same strings but from bottom to top like

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

[ 'r', 'xa, 'paw', 'tqyb', 'urbzi', 'nwsect', 'mxbih', 'rvoe', 'wig', 'ot', 't']

I tried to do that in my function by adding reversed() into the function like this

def diagsUpRight(M):
    n = len(M)
    m = [['']*i + row + ['']*(n-i-1) for i, row in enumerate(M)]
    return (reversed[''.join(col) for col in zip(*m)])

but the output prints None when I call it.

What am I doing wrong here, and what is the right code to get my desired output??

>Solution :

return [''.join(col[::-1]) for col in zip(*m)]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading