Reputation: 1109
please how can I add new values to the pos dictionary using the items in j as key and those in z as values
j = [3,5]
z = [(560,848), (833,934)]
pos = {2:(545,577), 4:(465,799)}
I tried
for i in z:
pos[j] = z[i]
but it gives this error: TypeError: list indices must be integers, not tuple.
Thanks
Upvotes: 0
Views: 42
Reputation: 5693
Use zip to create pairs that you can then convert into a dict. E.g.
pos = dict(zip(j, z))
If you want it more explicit that would be
pos = {}
for key, value in zip(j,z) :
pos[key] = value
Upvotes: 1