[Python] Separating/Adding lists together for a 2D array

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

  1. Stack

    Stack Membro Participativo

    Firstly I want to say thank you in advance for any and all help it's small for some but big for others and you have my gratitude!

    I have a list of numbers and need to analyze them in two different ways.
    [[ 0, 1, 0, 1, 0], [1, 1, 1, 1, 1], [ 0, 1, 1, 1, 0]]

    Firstly I need to add up any 1's and group them but ONLY if they're after each other. For this example:
    >>>[[1, 1], [5], [3]]
    (if 0 then post a 0)

    Then I need to add each row but one column at a time
    [[ **0**, 1, 0, 1, 0], [**1**, 1, 1, 1, 1], [ **0**, 1, 1, 1, 0]]
    >>>1
    (Continues to the next column)
    [[ 0, **1**, 0, 1, 0], [1, **1**, 1, 1, 1], [ 0, **1**, 1, 1, 0]]
    >>>3
    etc, etc.

    Thanks again!

    Continue reading...

Compartilhe esta Página