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

[ '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)]

Leave a Reply