* Added: dict_join to join several dicts, with keys from latter dicts taking

higher precedence.
master
wirawan 14 years ago
parent 582c7f25aa
commit ba3fcb6b6f
  1. 13
      sugar.py

@ -1,6 +1,6 @@
#!/usr/bin/ipython -pylab
#
# $Id: sugar.py,v 1.2 2010-02-08 19:58:44 wirawan Exp $
# $Id: sugar.py,v 1.3 2010-02-19 18:42:15 wirawan Exp $
#
# Created: 20100121
# Wirawan Purwanto
@ -52,3 +52,14 @@ def dict_slice(Dict, *keys):
"""
return dict([ (k, Dict[k]) for k in keys ])
def dict_join(*dicts):
"""Join multiple dicts into one, updating duplicate keys from left-to-right
manner.
Thus the key from the rightmost dict will take precedence."""
rslt = {}
for d in dicts:
rslt.update(d)
return rslt

Loading…
Cancel
Save