Week 09: Algorithms and File Operations
Week 09: Algorithms and File Operations
Outline
- Discuss homework assignments
- Sorting
- File input/output
Homework
Assignment 0
Download the plain text of Much Ado About Nothing from Project Gutenberg
Write a program to read in this file and count the total lines of dialog and the length (character count) of those lines for the two main characters: Benedick and Beatrice. Write that data out to a second file.
Feel free to modify the text file before loading it into Python if it’d be easier, for example, you want to strip out the starting and ending Project Gutenberg text, the scenes list, the dramatis personae, etc.
Assignment BONUS:
Implement a sorting algorithm for sorting a list of numbers. Don’t use any built-in sort. It can be as simple or complicated as you want. Feel free to look at the innumerable other examples on the Internet, but be prepared to explain your code!
Think back to what we talked about, to mapping human processes to code. Try your best, but don’t bang your head against a wall if you get stuck. I’m happy to chat about any of this material, of course.
def sort_numbers(numbers):
# your code here
return sorted_list
numbers = [6,3,7,8,1,3]
print(sort_numbers(numbers))