[Tutor] reverse diagonal

Ashfaq quazi.ashfaq at gmail.com
Sat Dec 1 17:01:52 CET 2012


>>> revdiag = [M[i][i] for i in [2, 1, 0]]
>>> revdiag
[9, 5, 1]

The reverse diag entries (that you are seeking to get) are not correct.
They should be M[0][2], M[1][1], M[2][0].
So the code could be --

revdiag = []
for i in [0, 1, 2]:
    j = 2 - i
    revdiag.append( M[i][j] )

I hope it helps.

--
Ashfaq
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20121201/4134fa49/attachment.html>


More information about the Tutor mailing list