Reputation: 57
I'm trying to set the keys in a dictionary from a list and the values from another list . but it's giving me this error and I'm not sure what's wrong :
code = {"" : "" , "" : "" , "" : ""}
keys = ["a" , "b" , "c"]
values = ["z" , "y" , "x"]
for x, k, v in zip(code, keys, values):
x = k
code[x] = v
print(code)
Upvotes: 1
Views: 76
Reputation: 48
You can try this.
keys = ["a" , "b" , "c"]
values = ["z" , "y" , "x"]
code=dict(zip(keys,values))
print(code)
Upvotes: 1
Reputation: 735
This is the right way of doing what you want
keys = ["a" , "b" , "c"]
values = ["z" , "y" , "x"]
code = {k:v for k,v in zip(keys,values)}
Upvotes: 1