Advertisement
Lewster7

Duplicate Remove

May 18th, 2022
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1.  #!/usr/bin/python
  2. # A very simple program to remove duplicates in a text file
  3. # How it works: Putt the text file in the same folder then after run script, follow the instruction
  4. # Made by Ali Ahmer aka King Ali
  5. # www.facebook.com/master.king.ali.333
  6.  
  7. def banner():
  8.     print('=====================================================')
  9.     print('|!!|      Duplicate Entry Remover        |!!|')
  10.     print('=====================================================')
  11.  
  12. banner()
  13.    
  14. inpt=input('Input Text file name e.g. input.txt :')
  15. oupt=input('Output file name e.g. output.txt :')
  16.    
  17. if __name__ == '__main__':
  18.     f = open(oupt,'w+')
  19.     flag = False
  20.     print('Please Wait. File in Process.....')
  21.     with open(inpt) as fp:
  22.         for line in fp:
  23.             for temp in f:
  24.                 if temp == line:
  25.                     flag = True
  26.                     print('Duplicate Found...!')
  27.                     break
  28.             if flag == False:
  29.                 f.write(line)
  30.             elif flag == True:
  31.                 flag = False
  32.             f.seek(0)
  33.         f.close()
  34. print('.../done')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement