fork download
  1. import collections
  2.  
  3. D1 = collections.OrderedDict()
  4. D1['first_key'] = 10
  5. D1['second_key'] = 20
  6.  
  7. D2 = collections.OrderedDict()
  8. D2['first_new_key'] = 123
  9. D2['second_new_key'] = 456
  10.  
  11. for (old_key, old_val), new_key in zip(list(D1.items()), D2.keys()):
  12. del D1[old_key]
  13. D1[new_key] = old_val
  14.  
  15. print(D1)
Success #stdin #stdout 0.04s 9360KB
stdin
Standard input is empty
stdout
OrderedDict([('first_new_key', 10), ('second_new_key', 20)])