Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!