06.0 Python‎ > ‎Python Projects‎ > ‎

Parse This (Python)

To parse something is to break it down into smaller parts.  For example to parse a sentence into words, you break out each word in the sentence.

Objectives

  • string processing -- find individual words
  • list processing -- keep track of all the words
    • sort the list
  • file processing -- read and write files

Program Description

Your program will need to:
  • read a text file
  • parse the text file into a list of words
  • count the number of words in the file
  • count the number of 1 letter, 2 letter, 3 letter ... all the way up to 10 letter words. Any word longer than 10 letters will count as a 10 letter word
  • count the number of occurrences of each word. Ignore the case (upper and lower case letters are treated as the same).
  • output the results to the screen and a new text file.

Program Road Map

  1. Read a text file into a string -- to start all words will be written in all lower case characters
  2. split the string into a list of words .split()
  3. sort the list of words list.sort()
  4. count the number of times each word is in the file.
  5. count the number of each 1 letter , 2 letter ... words
  6. format the output neatly on the screen and in the file




Comments