I need to take an n by n array and transpose it in Python-3. The example given is that I have this list input M:
[[4, 2, 1], ["a", "a", "a"], [-1, -2, -3]]
and it needs to be transposed to read:
[[4, 'a', -1], [2, 'a', -2], [1, 'a', -3]]
So basically reading vertically instead of horizontally.
I CANNOT use things like zip or numpy, I have to make my own function, trans(M).
If anyone could help and provide an explanation so I can learn it, I'd be grateful.
ith row,jth column element of A_transposed is thejth row,ith column element of A."zipor numpy"? E.g. are you not allowed to use any builtins (likezip), meaningrangeis off the table too? You can edit to clarify. And please mention what research you've done, e.g. if you already saw that question but matchew's answer doesn't meet your requirement because it usesrange, please tell us that to save us having to rehash it. For more tips, see How to Ask. [I know this is an old question, but I'm just giving the same advice I would to a new question.]