[Python] How do I split multiple dictionary rows by comma? (There are different numbers of...

Discussão em 'Python' iniciado por Stack, Maio 14, 2025.

  1. Stack

    Stack Membro Participativo

    I have an dict that contains 2 columns with multiple (over 100) rows. For example:

    {
    1 [12, 13, 25, 13, 25, 38, 56, 23]
    2 [1, 3, 65, 45, 3, 23]
    3 [4, 99, 120, 75, 12, 123, 24, 12]
    }


    etc.

    I'd like to split this up so each value in the 2nd column has its own column, but it's causing me some difficulty because there are different numbers of values in each 2nd column.

    I tried

    for key, value in dict.items():
    dict[key] = value.split(',')


    but got the error 'dict has no attribute split'

    Continue reading...

Compartilhe esta Página