0
votes

I'm trying to put values in a dictionary using following for loop. But python is throwing value error.

ValueError: too many values to unpack (expected 2)

acc_list = [KP_mse, Eminem_mse, shakira_mse, LMFAO_mse, Psy_mse]
artist_name= ['Katty Perry', 'Eminem', 'Shakira', 'LMFAO', 'Psy']
    dict = {}
    for (name,n) in (artist_name, acc_list):
        dict[name] =acc_list[n]
1
ARe you looking for zip() ? Additionally, are those unquoted things variables? - Jan
Please fix the indentation for your code. - wwii

1 Answers

4
votes

Use zip:

acc_list = [KP_mse, Eminem_mse, shakira_mse, LMFAO_mse, Psy_mse]
artist_name= ['Katty Perry', 'Eminem', 'Shakira', 'LMFAO', 'Psy']
dict = {}
for name, n in zip(artist_name, acc_list): #note the change from (name, n) to name, n
    dict[name] = n #note the change from dict[name] = acc_list[n]