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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started