SHARE
TWEET

merge two dictionaries (incorrect approach)

a guest Feb 22nd, 2019 85 in 218 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def foo(a, b):
  2.     a, z = dict(a), a.update(b) or a
  3.     print('a: {}; z: {}'.format(a, z))  # a: {1: 2}; z: {1: 2, 2: 3}
  4.  
  5.  
  6. d1 = {1: 2}
  7. d2 = {2: 3}
  8. print('d1 before', d1)  # {1: 2}
  9. foo(d1, d2)
  10. print('d1 after', d1)  # {1: 2, 2: 3}
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