mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-08-24 07:26:29 +00:00
Better dict merging (less side-effectful)
This commit is contained in:
parent
b6976eb6e9
commit
a241842ef9
1 changed files with 3 additions and 7 deletions
|
@ -32,15 +32,11 @@ def merge_dicts(*args):
|
||||||
def clone(obj):
|
def clone(obj):
|
||||||
copy = obj
|
copy = obj
|
||||||
if isinstance(obj, dict):
|
if isinstance(obj, dict):
|
||||||
copy = {}
|
copy = {key: clone(value) for key, value in obj.iteritems()}
|
||||||
for key, value in obj.iteritems():
|
|
||||||
copy[key] = clone(value)
|
|
||||||
if isinstance(obj, list):
|
if isinstance(obj, list):
|
||||||
copy = []
|
copy = [clone(value) for value in obj]
|
||||||
copy.extend(obj)
|
|
||||||
if isinstance(obj, set):
|
if isinstance(obj, set):
|
||||||
copy = set()
|
copy = set([clone(value) for value in obj])
|
||||||
copy.update(obj)
|
|
||||||
return copy
|
return copy
|
||||||
|
|
||||||
def merge(a, b, path=[]):
|
def merge(a, b, path=[]):
|
||||||
|
|
Loading…
Add table
Reference in a new issue