Python lab program 5
Python lab program 5
print(text)
words = text.split()
frequency = {}
Algorithm:
1. Start
2. Open the file named "sample.txt" in read mode.
3. Read the entire content of the file into a variable called text.
4. Print the content of the file to the output (optional for debugging/visualization).
5. Split the text into individual words using split() method and store them in a list called
words.
10.Print the top 10 most frequent words along with their counts.
11.End
Output:
Python is a popular general-purpose programming language. It is used in machine learning, web
development, desktop applications, and many other fields. Fortunately for beginners, Python has a
simple, easy-to-use syntax. This makes Python a great language to learn for beginners.
1st 10 most frequent words are{'Python': 3, 'a': 3, 'is': 2, 'for': 2, 'popular': 1, 'general purpose': 1,
'programming': 1, 'language.': 1, 'It': 1, 'used': 1}