Skip to content

Commit

Permalink
new dict support for commons
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Sep 15, 2015
1 parent 11aacc3 commit 60037a0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/commons/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

from . import dict
from . import structures

from .dict import dict_merge
from .structures import Decimal
13 changes: 13 additions & 0 deletions src/commons/dict.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

def dict_merge(first, second):
result = dict()
for key, value in first.items():
if key in second:
is_dict = isinstance(second[key], dict)
if is_dict: result[key] = dict_merge(value, second.pop(key))
else:
result[key] = value
for key, value in second.items(): result[key] = value
return result

0 comments on commit 60037a0

Please sign in to comment.