I have a textfile containing words, numbers, and characters. I want to delete all lines with the characters and words, and keep the lines with numbers. I found out that all those lines with words and characters have the letter of "r". so I wrote my code as:
The textfile contains these lines as an example:
-- for example
-- 7 Febraury 2022
5 7 1 5 3.0 2
3*2 3 5 7.0 3
and I want to keep these 2 lines:
5 7 1 5 3.0 2
3*2 3 5 7.0 3
This is the code written: textfile = open('test.txt', 'r') A = textfile.readlines()
L = []
for index,name in enumerate(A):
if 'r' in name:
L.append(index)
for idx in sorted(L, reverse = True):
del A[idx]
I know it is not a good way to do that, is there any suggestion to do that?