How to delete lines from text file when X character match in Python

1 Answer

0 votes
with open('d:\data.txt') as file:
    lines = file.readlines()
    result = []
    ch = 'a'
    for line in lines:
        if ch not in line:
            result.append(line)

with open('d:\data.txt', 'w') as file:
    file.writelines(result)


'''
run:

ccc ddd fff
hhh iii jjj
mmm nnn ooo

'''

 



answered Nov 1, 2017 by avibootz

Related questions

2 answers 250 views
1 answer 191 views
2 answers 262 views
1 answer 168 views
1 answer 269 views
...