Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

firstWords (fn)

Write the function firstWords 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.

The text of the Shakespeare play is taken from Folger Digital Texts. I have provided two exam- ples: A Midsummer Nights Dream and Romeo and Juliet on Canvas. If you choose, I encour- age you to generate more test data by downloading the texts of other Shakespeare plays from www.folgerdigitaltexts.org/download/ in txt format, then editing the play as defined below.

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 usedfirst. For example, BOTTOM, NICK. Or QUINCE, PETER. These are the only changes to the text. You may assume that any play that is used to test your code will follow these constraints. (Yes, I will use other plays in the autograder.)

To develop your algorithm, I suggest looking through the structure of the two Shakespeare plays I have given you. Please include your algorithm in the docstring of the firstWords func- tion. You should write other functions to divide and conquer your solution: please include docstrings for every function that you add. Please follow the 103 style guide conventions for docstrings: one-line definition of the function, parameters, return value (as illustrated in the functions of hw6_firstWords.py).

As you develop your code, you should use print statements to help you debug and understand your code; but remove them before you submit your code. (The tester will work if you just comment them out, so you can do that as you test, but please remove completely out of courtesy for the TA.) Also, just before submitting, test your code using the tester to verify that it passes.

here is the link to download the text: http://www.folgerdigitaltexts.org/download/

Download Romeo and Juilet, and A midsummer night's dream.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions