Choir 1¶
A choir has stored the information of its singers in a list
of tuples (tuple). Each tuple has three elements: the name
(str), the voice (str) that can be soprano, alto,
tenor or bass, and a Boolean (bool) showing whether the
singer can act as a soloist (True) or not (False).
Save the following functions into the same file choir.py
Write the function
singers_dict()that takes a list as described, and returns a dictionary (dict) in which keys are voices and values are lists of two elements: the number of singers with that voice (int) and the number of singers with that voice that can act as soloists (int). The dictionary must be complete taking into account the four mentioned voices. Example:>>> lcant = [('Josefina', 'alto', True), ('Pepet', 'bass', False), ... ('Josep', 'tenor', True), ('Fina', 'soprano', True), ... ('Pepeta', 'soprano', True), ('Josemari', 'tenor', True), ... ('Mariajo', 'soprano', False), ('Fineta', 'soprano', True), ... ('Xema', 'bass', True), ('Mariajosep', 'alto', True), ... ('Pep', 'tenor', True)] >>> d = singers_dict(lcant) >>> if d != {'bass': [2, 1], 'soprano': [4, 3], 'tenor': [3, 3], 'alto': [2, 2]}: ... print(d)
Note
You can download the file with tests
test-singers.txt.This choir has a dictionary for each musical piece of their repertoire with a structure similar to the dictionary computed in the previous function: keys are voices and values are lists of two elements: the number of singers with that voice and the number of soloists with that voice which are needed in this musical piece.
Write the function
feasible()that takes two dictionaries: a dictionary with the choir singers and a dictionary corresponding to a musical piece, and returns a Boolean (bool) with the value ofTrueif the choir has enough singers and soloists of each voice to represent this piece andFalseotherwise. Example:>>> dsingers = {'bass': [7, 1], 'soprano': [15, 3], 'tenor': [9, 0], 'alto': [10, 2]} >>> ave_verum = {'bass': [2, 0], 'soprano': [4, 0], 'tenor': [3, 0], 'alto': [2, 0]} >>> feasible(dsingers, ave_verum) True >>> cant_senyera = {'bass': [7, 0], 'soprano': [10, 0], 'tenor': [10, 0], 'alto': [10, 0]} >>> feasible(dsingers, cant_senyera) False >>> stabat_mater = {'bass': [6, 1], 'soprano': [10, 1], 'tenor': [6, 1], 'alto': [8, 1]} >>> feasible(dsingers, stabat_mater) False
Note
You can download the file with tests
test-feasible.txt.
Solutions
You have some solutions in file choir.py.