Python Program to Sort File Contents | File Handling | VTU Q6 | 1BPLC105B
Автор: Abdul Muqeet
Загружено: 2026-01-08
Просмотров: 52
Python Program to Sort the Contents of a Text File
VTU Model Question Paper – 1BPLC105B (Question 6)
In this video, I solve a Python programming question from the VTU Model Question Paper for the subject 1BPLC105B.
Question (6):
Develop a program to sort the contents of a text file and write the sorted contents into a separate text file. Use string methods strip() and list methods sort(), and file methods open(), readlines(), and write().
PYTHON SOLUTION USED
lines = open("input.txt").readlines()
cleaned = [line.strip() for line in lines]
cleaned.sort()
with open("output.txt", "w") as f:
for line in cleaned:
f.write(line + "\n")
CONCEPTS COVERED
File handling in Python
Reading file contents using readlines()
String processing using strip()
List operations and sorting
Writing data to a file
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 lab solutions and exam-oriented tutorials.
Доступные форматы для скачивания:
Скачать видео mp4
-
Информация по загрузке: