-
Notifications
You must be signed in to change notification settings - Fork 0
/
Comparison.py
51 lines (38 loc) · 1.12 KB
/
Comparison.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import sys
class Target:
def __init__(self):
self.foundList= {}
def parseFile(self,targetFile):
readFile = open(targetFile,'r')
for line in readFile:
line = line.strip('\n')
if self.foundList.has_key(line):
self.foundList[line] += 1
else:
self.foundList[line] = 1
readFile.close()
def startToCompareFiles(self,targetFile):
writeFile = open('compareResult.txt','w')
readFile = open(targetFile)
duplicatedItem = []
nonDuplicatedItem = []
for line in readFile:
line = line.strip('\n')
if self.foundList.has_key(line):
duplicatedItem.append(line)
else:
nonDuplicatedItem.append(line)
readFile.close()
duplicatedSet = list(set(duplicatedItem))
nonDuplicatedSet = list(set(nonDuplicatedItem))
writeFile.write("*******duplicated Item*******\n")
for data in duplicatedSet:
writeFile.write(str(data)+"\n")
writeFile.write("*******nonDuplicated Item*******\n")
for data in nonDuplicatedSet:
writeFile.write(str(data)+"\n")
writeFile.close()
if __name__=='__main__':
parser = Target()
parser.parseFile(sys.argv[1])
parser.startToCompareFiles(sys.argv[2])