Download Transpose Matrix.py
class Solution(object): def transpose(self, A): """ :type A: List[List[int]] :rtype: List[List[int]] """ R, C = len(A), len(A) ans = [[None] * R for _ in xrange(C)] for r, row in enumerate(A): for c, val in enumerate(row): ans[c][r] = val return ans # Alternative Solution: # return zip(*A) # def transpose(self, A): # res =  # for i in range(len(A)): # temp =  # for j in range(len(A)): # temp.append(A[j][i]) # res.append(temp) # return res
Leetcode 867 Transpose Matrix problem solution in python3 with explanation. This is the best place to expand your knowledge and get prepared for your next interview.
Feedback is the most important part of any website.
If you have any query, suggestion or feedback, Please feel free to contact us.