GH avatar Bite 151. Contemporary Composers

You are given a list of operas and a list of composers. For two given composers find operas (where one of the composers is the author) at which premiere both could have been together (i.e. they both had to be alive). Consider just a theoretical possibility of presence, so omit health condition, traveling problems, resources, and any other problems (excluding death) which could restrict their presence.

The list of operas consists of namedtuple('Opera', 'author play date') objects. The list of composers contains dictionaries with keys => composer names and values => namedtuple('Composer', 'name born died') objects.

Complete the operas_both_at_premiere(guest, composers) function. Parameters:

  guest - one of the composers but not the author of an opera
  composer - the author of an opera

If the required composer or guest is not in the list of composers, raise a ValueError exception. You can use the _get_date helper to convert date strings into datetime objects.

Return a list (or generator) of titles of operas. See the tests for more information.

Note that the list of operas in the Bite is shortened.

21 out of 21 users completed this Bite.
Will you be Pythonista #22 to crack this Bite?
It takes an average of ~47 minutes to solve this Bite (submissions 5-240 min).
Pythonistas rate this Bite 4.5 on a 1-10 difficulty scale.
» Up for a challenge? 💪

Buy Now Login and get coding
We use Python 3.7