Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use Python Code only. Please help me with this project.I have spent two days but still can't figure out what to do. I need codes

Use Python Code only.

Please help me with this project.I have spent two days but still can't figure out what to do. I need codes in python 3.3 or 3.6 only. you can dis regard C language.

Write a function that takes a lename and creates a single letter frequency distribution for all the chars (i.e. bytes) occurring in the le. Such a function in C might look roughly like the following:

void mkdist(float* D,char* filename)

{ FILE *fp = fopen(filename,"r");

/*write some code here to initialize some things*/

while((c=fgetc(fp))!=EOF) {

/*write some code here to process the char c*/

}

/*write some more code here to finish things up*/ fclose(fp);

}

I give you this code mainly to stop you from worrying about how to open a le, read from a le, and close the le. All of this is done for you but you still need to write the actual code to build the probability distribution. Remember that at the end of the method D[i] should be the number of occurrences of i in the le, divided by the total number of bytes (chars) in the le. Note that we wrote a Python implementation last class which opens a document and saves this distribution in a le. If you are using Python, you may modify this code to return a list of 26 numbers corresponding to the count of each letter in the alphabet.

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

Recommended Textbook for

Database Processing Fundamentals Design

Authors: Marion Donnie Dutton Don F. Seaman

14th Edition Globel Edition

1292107634, 978-1292107639

More Books

Students also viewed these Databases questions