forked from riteshsharma29/Python_find_duplicate_records
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind_duplicate_I.py
41 lines (30 loc) · 857 Bytes
/
find_duplicate_I.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
#!/usr/bin/python
# coding: utf-8 -*-
import codecs
from collections import Counter
def find_duplicate_1(filename):
#empty set
myset = set()
#empty list
mylist = []
#read records.txt file
filename = codecs.open(filename,encoding='utf-8')
log_file = codecs.open("log.txt",'w',encoding='utf-8')
log_file.write("Below values are duplicate" + '\n' + '\n')
#Iterate through the file
for rec in filename:
rec = rec.replace('\n',"")
if rec != "":
myset.add(rec)
mylist.append(rec)
#convert set into list
#all duplicates removed
newlist = list(myset)
c1 = Counter(mylist)
c2 = Counter(newlist)
diff = c1 - c2
#Print duplicate values
print list(diff.elements())
'''Change sample.txt with your file
call find_duplicate function'''
find_duplicate_1("sample.txt")