[Python] Pair all elements leaving alternate element in a list and form a new list of lists

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

  1. Stack

    Stack Membro Participativo

    I have a list which I would like to have unique element pairs generated for every alternate element

    List = [ L1, L2, L3, L4, L5, L6, L7,L8 ]

    List_in_pairs = [[L1,L3], [L2,L4], [L5,L7],[L6,L8]]


    I tried

    list_in_pairs = list(zip(List[::1], List[2::1]))


    but that doesn't seem to generate pairs as above fashion. Any insights?

    Continue reading...

Compartilhe esta Página