[Solved] How to fix “ValueError: not enough values to unpack (expected 2, got 1)”

I am trying to make a music app using tkinter and python, but I am not able to get rid of “ValueError: not enough values to unpack (expected 2, got 1)” bug. Have a look at my code and you’d be much clear with what I am dealing.

The mechanism is pretty simple, I, at first, display the song options via dictionary(list), and after taking the input, corresponding value of “j”,(example, if input is 1 then j is one and corresponding value of j is i) to be saved as the name of the song and execute the program by playing the music.

list = {
    '1':'Say You Won t Let Go.mp3','2':'In the Jungle the mighty jungle.mp3'
lost = ''
print("which one?")
this_one = int(input(''))
for j,i in list:
    if j == this_one:
        lost = i
Solution #1:

Here you go,

songs = {"1": "Say You Won t Let Go.mp3",
         "2": "In the Jungle the mighty jungle.mp3"}
lost = ''
this_one = int(input("Which One? "))

for number, song in songs.items():
    if number == this_one:
        lost = song

dict.items() returns a tuple of 2 objects, (Keys, values).

Respondent: Ibtihaj Tahir
Solution #2:

You have to use list.items()

for i, j in list.items():
Respondent: Vlad Balan
Solution #3:

Please try with items() as you are traversing over dict

for j,i in list.items():
Respondent: Harsha Biyani
The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy