Monday, November 14, 2016

Python - Combine Files/Lists, Strip Duplicates

This script reads in two files, turns them into lists, and removes all the duplicate values.  I used this to combine two files of thousands of MD5 hashes.



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
oldList=open("c:\\temp\\md5s_old.csv")
newList=open("c:\\temp\\md5s.csv")
old=[]
new=[]

for i in oldList:
 old.append(i)
oldList.close()

for i in newList:
 new.append(i)
newList.close()

old1=set(old)
new1=set(new)
uniques=new1-old1 
res=list(uniques)

f=open("c:\\temp\\uniqueMD5s.csv", 'w')
for i in res:
 f.write(i)
f.close()

No comments:

Post a Comment