Jump to content

Shakespeare: Difference between revisions

imported>Zanwenhuahao
imported>Zanwenhuahao
Line 144:
For more information on dictionary: https://docs.python.org/2/tutorial/datastructures.html#dictionaries
====<font color="navy">Lists and Dictionaries Exercises====
<b>List & Iteration Exercise 1:</b>
* Create a new python program.
* Import the list of characters from <b> A Midsummer Night's Dream </b> saved in the file <code>AMsND_Char.txt</code>
Line 156:
</pre>
 
<b>List & Iteration Exercise 2:</b>
* In the same program that you created from exercise 1
* Now open the play <b> A Midsummer Night's Dream </b>
Line 163:
* Close the file.
 
<b>List & Iteration Exercise 3*:</b>
* Use the same program as above
* Open the same play again
Line 172:
* <b>Note:</b> You can only readline() through a file once, so for each line read, you must check that if any of the characters have started a new speech that line.
 
<b>List & Iteration Exercise 4**:</b>
* Do the same as exercise 3, except now instead of printing them directly, save the <b>names of character</b> and <b>number of times they spoke</b> as a <b>key:value</b> pair in to a dictionary.
* Print the dictionary to screen and check that you have the same result as part 3.</font>
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.