A company sometimes needs to send two workers to perform repairs. To form the pairs, he has the data of the workers in a dictionary in which the key is the name of a worker and the value is the list with the names of the rest of the workers with whom they are disposed to work. Although worker ’pepe’ may be willing to work with ’paco’, it does not imply that ’paco’ is willing to work with ’pepe’. It is possible that some worker does not want to work with anyone.
Program a function limpia(preferencias) which, given a dictionary preferencias as described at the beginning, returns a new dictionary in which the names of the workers who are no longer in the company have been removed, that is, the ones that are no longer keys.
Scoring
Part 1: 45 puntos.
Part 2: 55 puntos.
>>> d1 = {'pep': ['pau', 'marc', 'eva'], 'pau': ['ana', 'lluc']} >>> d2 = limpia(d1) >>> d2 == {'pep': ['pau'], 'pau': []} True >>> serv = ['sabrenia', 'rowhn', 'storms'] >>> prefs = {'jennafer-lee': ['storms', 'sabrenia', 'sarma', 'nyera'], ... 'niloofar': ['jennafer-lee', 'rowhn', 'aaniah', 'brents'], ... 'sabrenia': [], ... 'rowhn': [], ... 'ishrat': ['aaniah', 'lyndell', 'lavarr', 'sarma', 'sanburn'], ... 'nyera': ['maxantia'], ... 'maxantia': ['nüket', 'storms', 'jerid', 'lavarr', 'nică'], ... 'sanburn': ['niloofar'], ... 'sarma': ['jerid', 'nüket', 'rowhn', 'sanburn'], ... 'aaniah': ['sabrenia', 'nică', 'niloofar', 'jennafer-lee'], ... 'nüket': ['nică', 'maxantia'], ... 'nică': ['storms', 'lavarr', 'sarma', 'rowhn'], ... 'storms': ['aaniah', 'maxantia', 'lavarr', 'nică']} >>> emp = empareja(serv, prefs) >>> emp == {'sabrenia': [], 'rowhn': [], 'storms': ['maxantia', 'nică']} True