daily pastebin goal
16%
SHARE
TWEET

Untitled

a guest Jun 13th, 2018 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. d1= { 'a': 1, 'b': 2, 'd': 6}
  2. d2= { 'c': 2, 'd': 3, 'b':4}
  3. d3 = {}
  4.  
  5. '''def merge(d1,d2):
  6.     dsum = {}
  7.     for k1 in d1:
  8.         for k2 in d2:
  9.             if d1 ==d2:
  10.                 k3 = d1
  11.                 dsum[k3] = d1[k1] + d2[k2]
  12.             else:
  13.                 dsum[d1] = d1
  14.                 dsum[d2] = d2
  15.                
  16.                
  17. print (merge2 (d1,d2)) '''
  18.  
  19. for d1_key, d1_value in d1.iteritems():
  20.     #print (str(d1_key) + " : " + str(d1_value))
  21.     d3[d1_key] = d1_value
  22.     print d3
  23.     for d2_key, d2_value in d2.iteritems():
  24.         #print (str(d1_key) + " : " + str(d1_value))
  25.         if d2_key in d3:
  26.             pass
  27.         else:
  28.             d3[d2_key] = d2_value
  29. print d3
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top