Answers for "how to concat two dictionaries in python"

1

how to merge two dictionaries in python

>>> x = {'a': 1, 'b': 2}
>>> y = {'b': 10, 'c': 11}
>>> z = {**x, **y} #In Python 3.5 or greater only
>>> print(z)
{'a': 1, 'b': 10, 'c': 11}
Posted by: Guest on April-30-2020
1

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()}}
Posted by: Guest on June-17-2021

Code answers related to "how to concat two dictionaries in python"

Python Answers by Framework

Browse Popular Code Answers by Language