[Python] Group list of lists based on a condition

Discussão em 'Python' iniciado por Stack, Junho 13, 2025.

  1. Stack

    Stack Membro Participativo

    I have a list of lists and I need to create groups: each group should be start by a pattern (the word "START" in this case) and should be end the line before the next pattern, here below the example:

    lst = [
    ["abc"],
    ["START"],
    ["cdef"],
    ["START"],
    ["fhg"],
    ["cdef"],
    ]

    group_a = [
    ["START"],
    ["cdef"],
    ]

    group_b = [
    ["START"],
    ["fhg"],
    ["cdef"],
    ]


    I tried with numpy and pandas too without any success. Many thanks in advance for your support. Regards Tommaso

    Continue reading...

Compartilhe esta Página