1

I have a dictionary of sets looking like this:

dictionary = {'0':{'apple','pear','banana'},'1':{'orange', 'apple'},'2':{'grape'}, '3': {'banana','peach'}

I would like to merge sets that have 1 or more of the same elements in the dictionary. Either keeping this dictionary or making a new one.

My goal is to have a dictionary like this:

dictionary = {'0':{'apple','pear','banana','orange','peach'},'1':{'grape'}}

The key names do not matter.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
  • 2
    What have you tried, and what exactly is the problem with it? And do the key names really matter so little that `'2': {'grape'}` can become `'1': {'grape'}` (if so, what's the point of the dictionary at all)? – jonrsharpe Apr 21 '20 at 12:50

0 Answers0