Creating a list of dictionaries via a for loop
I've been trying to create a list of dictionaries via a for loop, code shown below
a=["x","y","z"]
b=[1,2,3]
dict1={}
superlist=[]
for i in range(0,len(a)):
dict1['name']=a[i]
dict1['values']=b[i]
superlist.append(dict1)
What I'm expecting as my output is
[{'name':'x', 'values':1},{'name':'y', 'values':2},{'name':'z', 'values':3}]
,
instead I get
[{'name':'z', 'values':3},{'name':'z', 'values':3},{'name':'z', 'values':3}]
.
I'm not really sure what's going on here and it'd be great if someone can explain and help me get my desired result.