We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,633 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

python dictionaries

hi, am trying to work this one out for dictionaries. I have this 2 dict that i want to merge.

a= {16: {(7, 8, 0): {0: 4, 1: 5, 2: 6, 3: 7}, (7, 7, 0): {0: 0, 1: 1, 2: 2, 3: 3}}, 18: {(7, 8, 0): {0: 12, 1: 13, 2: 14, 3: 15}, (7, 7, 0): {0: 8, 1: 9, 2: 10, 3: 11}}}

b = {18: {(7, 7, 0): [0, 1, 2, 3]}}

So am trying to update the key, val pairs of b into a. I have tried a few ways but i always end up with this in a:

a= {16: {(7, 8, 0): {0: 4, 1: 5, 2: 6, 3: 7}, (7, 7, 0): {0: 0, 1: 1, 2: 2, 3: 3}}, 18: {(7, 8, 0): {0: 12, 1: 13, 2: 14, 3: 15}, (7, 7, 0): {[0, 1, 2, 3]}}}

I still want my 'a' to have the key,val pairs instead of just a list of values, here is the code i tried :
for (c,d,e), k_v in a[grp].iteritems():
... for (c,d,e),new in b[grp].iteritems():
... new=b[grp][c,d,e]
... a[grp][c,d,e]=new

This is how i would like to have my a :

a= {16: {(7, 8, 0): {0: 4, 1: 5, 2: 6, 3: 7}, (7, 7, 0): {0: 0, 1: 1, 2: 2, 3: 3}}, 18: {(7, 8, 0): {0: 12, 1: 13, 2: 14, 3: 15}, (7, 7, 0): {0: 0, 1: 1, 2: 2, 3: 3}}}

Any help will be much appreciated...thanks

1
Contributor
0
Replies
1
View
gsr
Newbie Poster
4 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0586 seconds using 2.67MB