Pairs X13504


Statement
 

pdf   zip

html

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.

  1. When a worker leaves the company his entry is deleted from the dictionary, but the name may continue to appear on other workers’ lists.

    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.

  2. The company needs to send workers to make repairs. Program a function empareja(ltrab, preferencias), which given a list ltrab of company workers each destined for a different repair, and a dictionary preferencias like the one described at the beginning, returns a dictionary that associates each employee assigned to repairs with the possible companions (those who are they prefer each other but are not intended for another repair service).

Scoring

Part 1: 45 puntos.

Part 2: 55 puntos.

Sample session
>>> 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
Information
Author
InfBesos
Language
English
Translator
Original language
Spanish
Other languages
Catalan Spanish
Official solutions
Python
User solutions
Python