Question: Using Pycharm (Python). Program must have a header. gettysburg.txt file - Four score and seven years ago our fathers brought forth on this continent, a
Using Pycharm (Python). Program must have a header.

gettysburg.txt file -
Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal. Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived and so dedicated, can long endure. We are met on a great battle-field of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live. It is altogether fitting and proper that we should do this. But, in a larger sense, we can not dedicate -- we can not consecrate -- we can not hallow -- this ground. The brave men, living and dead, who struggled here, have consecrated it, far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here dedicated to the great task remaining before us -- that from these honored dead we take increased devotion to that cause for which they gave the last full measure of devotion -- that we here highly resolve that these dead shall not have died in vain -- that this nation, under God, shall have a new birth of freedom -- and that government of the people, by the people, for the people, shall not perish from the earth. Abraham Lincoln November 19, 1863
We will create a program which performs three essential operations. It will process this.txt file: Gettysburg.txt. (Click the link to download the text file). Calculate the total words, and output the number of occurrences of each word in the file. Open the file and process each line. Either add each word to the dictionary with a frequency of 1 or update the word's count by 1. Nicely print the output, in this case from high to low frequency. You should use string formatting for this. (See discussion 8.3). We want to achieve each major goal with a function (one function, one action). We can find four functions that need to be created. add word: Add each word to the dictionary. Parameters are the word and a dictionary. No return value. Process_line: There is some work to be done to process the line: strip off various characters, split out the words, and so on. Parameters are a line and the dictionary. It calls the function add word with each processed word. No return value. Pretty_print: Because formatted printing can be messy and often particular to each situation (meaning that we might need to modify it later), we separated out the printing function. The parameter is a dictionary. No return value. main: We will use a main function as the main program. As usual, it will open the file and call process_line on each line. When finished, it will call pretty_print to print the dictionary. In the main function, you will need to open the file. We will cover more regarding opening of files next week but I wanted to provide you with the block of code you will utilize to open the file, see below. gba_file = open('gettysburg.txt', 'r') for line in gba_file: #do some stuff ....... Example Output from the Program: Length of the dictionary: 143 Word Count - - - that the we to NOE here and of not nation have for can this UWA AU in onu dedicated who us
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
