Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using Pycharm (Python) modify our Gettysburg processing program in order to generate a text file from the output rather than printing to the screen. Your

Using Pycharm (Python) modify our Gettysburg processing program in order to generate a text file from the output rather than printing to the screen. Your program should have a new function called process_file which prints to the file (this method should almost be the same as the pretty_print function from last week. Keep in mind that we have print statements in main as well. Your program must modify the print statements from main as well. Your program must have a header. Create a new function called process_fie. This function will perform the same operations as pretty_print from week 8 however it will print to a file instead of to the screen. Modify your main method to print the length of the dictionary to the file as opposed to the screen. This will require that you open the file twice. Once in main and once in process_file. Prompt the user for the filename they wish to use to generate the report. Use the filename specified by the user to write the file. This will require you to pass the file as an additional parameter to your new process_file function. The output should be from high to low frequency (text) and use string formatting for this.

I do not understand how to put it in frequency order from high to low and not sure on the printing the file.

main_dict = {} def add_word( dataVal ): count = 1 if dataVal in main_dict: main_dict[dataVal] = main_dict[dataVal] + count else: main_dict.update({dataVal: count}) def Process_line( data ): data_list = data.split(" ") for val in data_list: add_word(val.replace(" ", "").replace(",", "").replace(".", "").replace("-", "")) def Pretty_print(): print("length of the dictionary:", len(main_dict)) print("word\tcount ") print("-------------") for key, val in main_dict.items(): print("{}\t{}".format(key, str(val))) if __name__ == "__main__": f = open("gettysburg.txt", "r") for line in f.readlines(): Process_line(line) print(Pretty_print()) 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

9-20 In terms of temporal factors, what does slow or fast mean?

Answered: 1 week ago

Question

5. Identify three characteristics of the dialectical approach.

Answered: 1 week ago

Question

6. Explain the strengths of a dialectical approach.

Answered: 1 week ago

Question

4. Explain the strengths and weaknesses of each approach.

Answered: 1 week ago