Starting from:
$30

$24

Closed Lab 1 Lists and Files Solution

Description: Along with this document, you downloaded two data les: shakespeare.txt and characters.txt. The former contains, according to Project Gutenberg, the com-plete works of William Shakespeare in plain text. The latter contains the names of 50 of Shakespeare’s characters, again in plain text. Your mission, should you choose to accept it (no, you don’t really have a choice), is to count the number of times each character is mentioned in the text of the plays.







Almost all of the Python methods you will need are in the examples we have looked at in class. In particular, open for opening a le and readlines for reading a le into list will be useful. The result of readlines will be a list of strings. Recall that you can use split to tokenize a string into a list of \words." However, you can instead apply many list operations to strings as well. Either approach is valid.




Details: Recall that Shakespeare wrote plays. Thus, the shakespeare.txt le contains not only what the characters said but also labels indicating which character speaks. The labels are in all caps; you should not count these occurrences of the characters’ names.




characters.txt contains one character per line.




Your program should produce concise, easy-to-read output that reports the number of occurrences of each character’s name.



































































1

More products