[Python] How do I transpose rows to columns with a triangular array?

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

  1. Stack

    Stack Membro Participativo

    I want to convert a lower triangle to an upper triangle so that the rows become columns. I have the following list of lists:

    [[-1]
    [-2, -2]
    [-2, -1, -2]
    [-3, 0, -1, -3
    [-3, 2, 1, -1, -3]
    [-4, 4, 3, 1, -1, -4]
    [-4, 7, 6, 4, 2, -1, -4]
    [-5, 10, 9, 7, 5, 2, -1, -5]
    [-5, 14, 13, 11, 9, 6, 3, -1, -5]
    [-6, 18, 17, 15, 13, 10, 7, 3, -1, -6]
    [-6, 23, 22, 20, 18, 15, 12, 8, 4, -1, -6]
    [-7, 28, 27, 25, 23, 20, 17, 13, 9, 4, -1, -7]
    [-7, 34, 33, 31, 29, 26, 23, 19, 15, 10, 5, -1, -7]
    [-8, 40, 39, 37, 35, 32, 29, 25, 21, 16, 11, 5, -1, -8]
    [-8, 47, 46, 44, 42, 39, 36, 32, 28, 23, 18, 12, 6, -1, -8]
    [-9, 54, 53, 51, 49, 46, 43, 39, 35, 30, 25, 19, 13, 6, -1, -9]
    [-9, 62, 61, 59, 57, 54, 51, 47, 43, 38, 33, 27, 21, 14, 7, -1, -9]
    [-10, 70, 69, 67, 65, 62, 59, 55, 51, 46, 41, 35, 29, 22, 15, 7, -1, -10]]


    Do I need to pad the rows with zeros so that zip can do this?

    Continue reading...

Compartilhe esta Página