Skip to content
Advertisement

Creating a word length frequency table in python

I have the following code:

JavaScript

Without importing anything else, how would I make a table which prints the length and then the frequency.

For example: In a file with the text of “a blah ba ba” it would print:

JavaScript

What confuses me about this is how to add all the length of the words together, should I be making a new list with all the same length of words and then counting the length of that list, or is there a better way to do it.

Advertisement

Answer

JavaScript

Then you can print the two columns:

JavaScript

EDIT: To handle empty files:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement