Each time through the outer loop, you attempt to completely erase image
and then append the most recently computed row
to it. But this is your source data; the next time through the outer loop, you attempt to build the next row with row.append(image[n][m])
as if nothing had happened.
You are already using result
to accumulate the result; don't modify image
during the process. Not only does it cause the problem you are seeing, but it is bad interface design: the person using your code (which will probably be you, months from now when you have forgotten what you were thinking) will very definitely not expect the value of image
to change at all when computing the transposed version and giving it a separate name.
You have a list named result
, and you are apparently doing this inside a function; the natural thing to do would be to return result
, and not modify any of the input data. If for some reason you had to modify the input list, then the way to do that is to assign the contents of result
back into the image
list, a single time, after all the loops: something like image[:] = result
. But in this case, there is no good reason to return
anything; return True
doesn't mean anything useful (if something went wrong, you should not return False
or any other value; you should instead raise an Exception - that's what they're for). Since in this case the calling code gets all the information it needs by just using the modified version of image
after calling the function, the return value is useless. The standard library also adopts this convention.