[Python] convert a list which has single elements and lists into a flat list

Discussão em 'Python' iniciado por Stack, Novembro 30, 2024.

  1. Stack

    Stack Membro Participativo

    How would you convert a list like this :

    ["foo",["banana","apple"], "banana", ["peaches","grapes"]]


    into

    ["foo","banana","apple", "banana", "peaches",'grapes"]


    I tried:

    flat_list = [item for sublist in regular_list for item in sublist]

    Continue reading...

Compartilhe esta Página