Let's say I have two dicts where the values are lists (or sets are also fine since the contents are unique). For example:
dic1 = {'math': ['algebra', 'trigonometry', 'geometry']}
dic2 = {'math': ['calculus'], 'science': ['physics']}
dic2.update(dic1)
My desired output would be this:
{'math': ['algebra', 'trigonometry', 'geometry', 'calculus'], 'science': ['physics']}
but instead I get:
{'math': ['algebra', 'trigonometry', 'geometry'], 'science': ['physics']}
Essentially I want to combine the contents when merging the two dicts (I don't want to override but rather retain both). Is there a simple way to do this? Note: In this this example I gave, there are only two dictionaries. Although I did not write the code yet, I would ultimately want to loop over several dictionaries and do this process of merging/updating in the loop, which might be helpful while suggesting an approach.