To merge two dictionaries with list values in Python, you can use the update()
method of the dictionary.
Here is an example:
main.py231 chars11 lines
Output:
main.py82 chars2 lines
In the above example, we iterate over each key in dict2 and check if it is present in dict1. If it is present, we extend the list in dict1 with the list in dict2 for the corresponding key. If it is not present, we simply add the key-value pair from dict2 to dict1.
gistlibby LogSnag