我发现了这个想法的变体,但没有一个可以让我(对 python 非常陌生)到达我需要的地方。
这是场景:
hashfile.txt由单独的字符串组成。addresses.txt文件中搜索匹配项outfile.txt我当前的代码已尽我所能优化,但只有 150 行/秒左右。考虑到我有超过 15 亿行hashfile.txt,任何优化都会有所帮助。
fin = 'hashed.txt'
nonzeros = open('addrOnly.txt', 'r')
fout = open('hits.txt', 'w')
lines = nonzeros.read()
i = 0
count = 0
with open(fin, 'r') as f:
for privkey in f:
address = privkey.split(", ")[0]
if address in lines:
fout.write(privkey)
i = i+1
if i%100 == 0:
count = count + 100
print "Passed: " + str(count)
Run Code Online (Sandbox Code Playgroud)