[Python] How to fix ValueError: too many values to unpack (expected 3) in Python?

Discussão em 'Python' iniciado por Stack, Dezembro 19, 2024.

  1. Stack

    Stack Membro Participativo

    I have a dataset called records, a dataset sample looks like:

    user_id movie_id genre
    1 1001 action
    2 1002 drama
    3 1003 comedy
    4 1004 drama
    ... ... ...


    I would like to iterate over records in the following way:

    for user, movie, genre in records:
    print(user, movie, genre)


    It first prints some rows and then shows this error:

    44892 113769 comedy
    44892 113769 drama
    ...
    ------------------------------------------------
    ValueError Traceback (most recent call last) in
    ----> 1 for user, movie, genre in records:
    2 print(user, movie, genre)

    ValueError: too many values to unpack (expected 3)


    What is wrong and how to fix it?

    Continue reading...

Compartilhe esta Página