From 353570725a26acb722f37c842f4c7ea2c7ecf3f8 Mon Sep 17 00:00:00 2001 From: minoplhy Date: Fri, 11 Mar 2022 14:25:34 +0700 Subject: [PATCH] duplicat : init --- duplicat.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 duplicat.py diff --git a/duplicat.py b/duplicat.py new file mode 100644 index 0000000..80e7007 --- /dev/null +++ b/duplicat.py @@ -0,0 +1,32 @@ +def add_file(input, output): + with open(input, 'r') as f: + lines = f.read().split() + with open(output, 'a') as f: + for line in lines: + f.write('\n'.join([line + '\n'])) + f.close() + print('Getting rid of duplicated line') + with open(output, 'r') as f: + lines = set(f.readlines()) + with open(output, 'w') as f: + f.writelines(set(lines)) + f.close() + +def check_n_kill_dupes(duperuleset, input): + with open(duperuleset, 'r') as s: + ruleset = s.read().split() + with open(input, 'r') as f: + lines = f.read().split() + with open(input, 'w') as f: + for line in lines: + if not line in ruleset: + f.write('\n'.join([line + '\n'])) + f.close() + # Remove Blank Line + with open(input ,'r') as f: + lines = f.read().split() + with open(input ,'w') as f: + for line in lines: + if line.strip(): + f.write('\n'.join([line + '\n'])) + f.close() \ No newline at end of file