[Python] Convert list items to list if not list in python

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

  1. Stack

    Stack Membro Participativo

    There is a list like that:

    mylist = [[1,2,3], 7, [4,5,6], [7,8,9], 5]


    As you notice, it is a list of nested lists and that is OK... But there are some items in the mylist which are not considered a list. How can I convert those to nested lists too?

    I mean the output should be like that:

    mylist = [[1,2,3], [7], [4,5,6], [7,8,9], [5]]

    Continue reading...

Compartilhe esta Página