Question: In Python 3 Write the function dictionary(fn) that, given the filename fn of a Shakespeare play from Folger Digital Texts, builds and returns a Python

In Python 3

Write the function dictionary(fn) that, given the filename fn of a Shakespeare play from Folger Digital Texts, builds and returns a Python dictionary that records, for each character, the number of speeches of the character, the act of the first speech of the character, and the scene of the first speech of the character. The keys of the dictionary are character names, where a character name is defined as the first words listed for a character (e.g., BOTTOM). The value associated with this key is a list of 3 integers. The dictionary entry for Juliet in Romeo and Juliet should be 'JULIET': [118, 1, 3] since Juliet first speaks in Act 1, Scene 3 and has 118 speeches in the play. If a character speaks that is not in the list of characters of the play (e.g., CITIZENS in Romeo and Juliet), simply ignore it (no dictionary entry). If a character never speaks (e.g., CHORUS in Romeo and Juliet), you should still have a dictionary entry for this character, and simply set its act and scene to 0: 'CHORUS' : [0, 0, 0]. The first speech is defined by the act and scene that the character first speaks , not the first time they are mentioned. You may assume that act and scene are recorded as in the Folger Digital Texts: (e.g., ACT 1, Scene 1). You may assume that the words ACT and Scene only occur at the beginning of a line when they are recording an act or scene. You may assume that acts and scenes begin at 1 and increase by 1 each time. A character is defined as a character in capital letters in the section called Characters in the Play. When a character speaks, later in the play, their name is listed in all-caps at the beginning of the line. I have edited the text so that the first name in the list of characters is always the same as the name used later in the play to refer to that characters speech. In particular, there are two types of change: 1) if a character has two names and the text uses both names, these names are combined into one (FRIAR LAWRENCE becomes FRIARLAWRENCE). 2) if a character has two names and only one is used (e.g., NICK BOTTOM uses BOTTOM), I have placed the name that is used first . For example, BOTTOM, NICK. Or QUINCE, PETER. Please include your algorithm in the docstring of the dictionary(fn) function. You should write other functions to divide and conquer your solution: please include docstrings for every function that you add.

.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!