Python Program to Find Top 10 Frequent Words in a File | VTU Q4 | 1BPLC105B
Автор: Abdul Muqeet
Загружено: 2026-01-07
Просмотров: 54
Python Program to Find 10 Most Frequently Appearing Words in a Text File
VTU Model Question Paper – 1BPLC105B (Question 4)
In this video, I solve a Python programming question from the VTU Model Question Paper for the subject 1BPLC105B.
Question (4):
Develop a program to print the 10 most frequently appearing words in a text file. Use a dictionary with distinct words and their frequency of occurrences. Sort the dictionary in reverse order of frequency and display the first 10 items.
PYTHON SOLUTION USED
text = open("sample.txt").read().lower()
word = text.split()
freq = {}
for w in word:
freq[w] = freq.get(w, 0) + 1
top10 = sorted(freq.items(), key=lambda x: x[1], reverse=True)[:10]
for word, count in top10:
print(word, ":", count)
CONCEPTS COVERED
File handling in Python
String processing
Dictionary for frequency counting
get() method
Sorting using lambda function
Slicing lists
This video is useful for
VTU students
First year engineering students
Python beginners
Exam and viva preparation
Like, Share, and Subscribe for more VTU Python programming solutions and exam-oriented tutorials.
Доступные форматы для скачивания:
Скачать видео mp4
-
Информация по загрузке: