[Python] Test if a variable is a list or tuple

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

  1. Stack

    Stack Membro Participativo

    In python, what's the best way to test if a variable contains a list or a tuple? (ie. a collection)

    Is isinstance() as evil as suggested here? http://www.canonical.org/~kragen/isinstance/

    Update: the most common reason I want to distinguish a list from a string is when I have some indefinitely deep nested tree / data-structure of lists of lists of lists of strings etc. which I'm exploring with a recursive algorithm and I need to know when I've hit the "leaf" nodes.

    Continue reading...

Compartilhe esta Página