Answer the question
In order to leave comments, you need to log in
How to delete a line with 20 characters in python?
Hello, there is a text file with a large number of lines, and some lines are repeated in it, but not completely, how can I make sure that lines in which less than 20 characters are deleted?
Answer the question
In order to leave comments, you need to log in
with open(file, 'r') as f:
lines = f.readlines()
new = [line for line in lines if len(line) < 20]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question