Question: Write a Python function that takes a filename and creates a single letter frequency distribution for all the chars (i.e. bytes) occuring in the file.

Write a Python function that takes a filename and creates a single letter frequency distribution for all the chars (i.e. bytes) occuring in the file.

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);

}

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.

Incorporate what the actual code is to build the probability distribution.

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!