9. Write a python program to calculate the frequency of a all the words in a file, a.txt.
The output is:
Original file a.txt:
Welcome to
www.freelearningpoints.com
You can learn Python tutorials and
practice with exercises
To practice with more exercises and
enhance the skills.
Expected Answer:
The total number of each words in the file :
Counter({'Welcome': 1, 'to': 1, 'www.freelearningpoints.com': 1, 'You': 1, 'can': 1, 'learn': 1,
'Python': 1, 'tutorials': 1, 'and': 1, 'practice': 1, 'with': 1, 'exercises': 1})
Sample Answer:
from collections import Counter def word_count(file_name): with open(file_name) as f: return Counter(f.read().split()) print("The total number of each words in the file :") print(word_count("a.txt"))
More Exercises:
Python String ExercisesMore Numpy Exercises:
Numpy String ExercisesMore Pandas Exercises:
Pandas Series ExercisesMore Tutorials:
Python Installation - Linux (Ubuntu)