[Python] How to transpose an array in Python 3?

Discussão em 'Python' iniciado por Stack, Abril 16, 2025.

  1. Stack

    Stack Membro Participativo

    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.

    Continue reading...

Compartilhe esta Página