I have a dictionary that resembles the following:
dict1 = {'key1':['1','2','3'],'key2':['3','4','5'],'key3':['6','7','8']}
I would like to merge all keys that have at least one common element and as a result. For example, the resulting dictionary should look like:
dict1 = {'key1':['1','2','3','4','5'],'key3':['6','7','8']}
Please note how key2 has been eliminated. Whether it is key1 or key2 that is eliminated does not matter. I have only gotten as far as being able to identify repeats, but not how to merge them in an iterative fashion. Thanks
If you want to change the original dict you will need to copy:
If you want to union all: