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):
|
||||
copy = obj
|
||||
if isinstance(obj, dict):
|
||||
copy = {}
|
||||
for key, value in obj.iteritems():
|
||||
copy[key] = clone(value)
|
||||
copy = {key: clone(value) for key, value in obj.iteritems()}
|
||||
if isinstance(obj, list):
|
||||
copy = []
|
||||
copy.extend(obj)
|
||||
copy = [clone(value) for value in obj]
|
||||
if isinstance(obj, set):
|
||||
copy = set()
|
||||
copy.update(obj)
|
||||
copy = set([clone(value) for value in obj])
|
||||
return copy
|
||||
|
||||
def merge(a, b, path=[]):
|
||||
|
|
Loading…
Add table
Reference in a new issue