Reputation: 1
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
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