Nataraj Beelagi
Nataraj Beelagi

Reputation: 1

python: ValueError: too many values to unpack (expected 2)

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]

Upvotes: 0

Views: 1513

Answers (1)

mauve
mauve

Reputation: 2763

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]

Upvotes: 4

Related Questions