Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python merge dictionaries

def merge_dicts(dict1, dict2):
        """Here's an example of a for-loop being used abusively."""
        return {**dict2, **{k: (v if not (k in dict2) else (v + dict2.get(k)) if isinstance(v, list) else merge_dicts(v, dict2.get(k))) if isinstance(v, dict) else v for k, v in dict1.items()}}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #merge #dictionaries
ADD COMMENT
Topic
Name
2+5 =