Rotate Matrix using Python
You can use much simpler algorithm in python:
Transpose matrix:

zip(*matrix)


Inverse rows in transposed matrix (equals rotation right):

list(list(x)[::-1] for x in zip(*matrix))


However, if you want to rotate left, you need first inverse rows and then transpose, which is slightly more code.