Can Computers Think?
Introduction to Computer Science

CSC 106
Union College
Winter 2010

Homework exercise to prepare for class on Wednesday, March 3rd

Given code and input files

Turning the word frequency dictionary into a sorted list

The function build_word_dictionary in build_word_frequency_dictionary.py reads in a text file and creates a dictionary that records all different words used in the text file and how often they were used. That is, the keys of the dictionary are strings (the words) and the values are numbers (the frequencies).

Sorting the words alphabetically

Write a function that takes a word frequency dictionary as parameter and returns a list containing all dictionary entries. The entries in the list should be in alphabetical order. For example, the entries for words starting with 'a' should come before the entries for words starting with 'b'.

Sorting by frequency

Write a function that takes a word frequency dictionary as parameter and returns a list containing all dictionary entries. The entries in the list should be ordered by their frequency value. That is, words that are not so frequent in the text should come before words that occur more frequently.

Submit on Blackboard