Write a Python function shared_values that takes a dictionary where the keys are strings, and the values are integer lists. The function will return a new dictionary, where for each key/value pair, the key is an integer, and the value is a list of strings. The keys of the resulting dictionary will correspond to the values in the original dictionary, and the values will be the keys from the original dictionary that shared a value in common.

Respuesta :

Answer:

Python code explained below

Explanation:

CODE:

def shared_values(d):

   key = list(d.keys())

   val = []

   # Collecting all values in a list irrespective of key

   for k in key:

       for v in d[k]:

           if not v in val:

               val.append(v)

               

   #Creating new dictionary    

   new_d={}

   for i in val:

       for j in key:

           if i in d[j]:

               if i in new_d.keys():

                   new_d[i].append(j)

               else:

                   new_d[i] = [j]

   return new_d

print(shared_values({'a':[3,11,2],'b':[2,3,7],'c':[5,7]}))