0

I'm kind've stuck on this problem! I have a massive text file (3 million lines or so) and I need to remove any lines that contain more then one tilde. Could someone be as kind to help me out! Please and thank you .

Here is what I have so far:

import re 

f_in = 'C:\\Users\\John\\Documents\\Python\\Pagelinks\\pagelinkSample_10K_cleaned2.txt'

f_out = 'C:\\Users\\John\\Documents\\Python\\Pagelinks\\pagelinkSample_10K_cleaned3.txt'

with open(f_in, 'r') as fin: 

        with open(f_out, 'w') as fout: 

              for line in fin: 

stuck here, i'm thinking if line count for tilde contains more then one delete line?

Thanks!

idjaw
  • 25,487
  • 7
  • 64
  • 83
lsch91
  • 335
  • 3
  • 11

1 Answers1

3
for line in fin:
    if line.count('~') < 2:
        fout.write(line)
hilberts_drinking_problem
  • 11,322
  • 3
  • 22
  • 51