Reputation: 127
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(list)
print("which one?")
this_one = int(input(''))
for j,i in list:
if j == this_one:
lost = i
Upvotes: 6
Views: 21980
Reputation: 636
Here you go,
songs = {"1": "Say You Won t Let Go.mp3",
"2": "In the Jungle the mighty jungle.mp3"}
lost = ''
print(songs)
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).
Upvotes: 3
Reputation: 7268
Please try with items()
as you are traversing over dict
for j,i in list.items():
Upvotes: 2