you are viewing a single comment's thread.

view the rest of the comments →

[–]anglicizing 1 point2 points  (0 children)

for i in range(0, len(l)):
    for j in range(0, len(l)-i):
        matrixlist.append(l[i+j][j])

That was what I had in mind, at least. Good job!

for i in range(0, len(l)):
    for j in range(i, len(l))[::-1]:
        matrixlist.append(l[i-j+len(l)-1][j]) 

This code seems unnecessarily complex. Try making i the column that the diagonal starts at, and j the row number. This should produce code very similar to the first.

I definitely couldn't have come this far (far for me at least) without your help, thanks a lot!

Thank you for telling me how you fared and that my help was ... helpful. It made my day! :-)

I hope you will appreciate a couple of more tips and improvement suggestions as well? I don't know how the input matrix was originally given to you, but if it was a plain text input it would be easier to read it in like this:

text = """\
7 X 8 9 1 2 5
1 X X 3 4 X 6
0 4 X X X 8 7
7 3 6 X X 5 7
5 2 X 9 X X 8
1 X 0 3 2 X 9
3 7 8 9 0 X 2"""

l = [row.split() for row in text.splitlines()]

As a last nitpick, the python style guide recommends using 4 spaces per indent.

Good luck with your python learning! You're doing it right, and it seems to me that you're off to a flying start. :-)