-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdedup.py
More file actions
20 lines (20 loc) · 671 Bytes
/
Copy pathdedup.py
File metadata and controls
20 lines (20 loc) · 671 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import os
os.rename(r'lists/scam.txt',r'lists/scam-pre.txt')
# This program opens file
# input file bar.txt and removes duplicate lines and writes the
# contents to
# output file foo.txt file.
lines_seen = set() # holds lines already seen
outfile = open('lists/scam.txt', "w")
infile = open('lists/scam-pre.txt', "r")
print("The file test-pre.txt is as follows")
for line in infile:
print(line) #line
if line not in lines_seen: # not a duplicate
outfile.write(line)
lines_seen.add(line)
outfile.close()
print("The file lists/scam.txt is as follows")
for line in open('lists/scam.txt', "r"):
print(line) #line
os.remove("lists/scam-pre.txt")