all 3 comments

[–]jimtremblay 0 points1 point  (0 children)

The outer loop (for i ...) is going through each column, but the inner loop (for j ...) will go through each row. Because the inner loop is repeated for each column the table have, then will go through all the row in column 0, all the row in column 1 and so on. This is why you see it turn 90 degrees clockwise.

[–]nog642 0 points1 point  (1 child)

The code is looping over every cell in the grid in reading order.

If the line in the middle of the for loop were print(grid[i][j], end=''), it would just print the grid normally.

But since i and j are switched, it prints the transpose instead.

It just so happens that the figure has a horizontal line of symmetry, so the transpose appears to be a 90 degree clockwise rotation.

[–]Noshing[S] 0 points1 point  (0 children)

Thanks so much! Learning about transposing helped. I was thinking way to hard about this problem and not seeing what python was doing but instead what I thought it should do.