def findDiagonalOrder(self, matrix):
return [matrix[i][j] for i, j in
sorted([(i, j) for i in range(len(matrix)) for j in range(len(matrix))],
key=lambda (i, j): (i + j, (j, i)[(i + j) & 1]))
] if any(matrix) else 
I like this solution because it only requires two conditional statements per update, whereas the more straightforward solutions will perform ~5 checks per update in large matrices. You could even get that down to just the bounds check by duplicating your inner for loop, but hopefully the branch prediction gets the parity check guess right because it's not changing.