하나의 파일에서 다른 행의 값을 검색하고 있습니다. 정확한 값은 검색 파일에서 한 번만 발생합니다. 이 프로세스를 더 빨리 수행하려면 어떻게해야합니까? 다음은 현재 코드입니다.파이썬에서 어떻게 빨리 검색 할 수 있습니까?
filltaxlist = open("file with query number.txt", "rw")
fulltaxa = open("output file with hit line match", "rw")
for line in filltaxalist:
line = line.strip()
taxid = re.split("\t", line)
lookup = taxid[5] # this value is a number and I need the exact match only so I convert it to an integer
int1 = int(lookup)
for line in open("File to search.txt", "r"):
data = re.split(',', line)
hit = int(data[0]) # every value in this file is a number separated by a ,
if lookup in line:
if int1 == hit:
fulltaxa.write(line)
매우 느리게 작성되었으므로 잘 작동합니다. 또한 내가 검색하는 파일의 크기가 GB 이상입니다. filltaxlist
라인의
예 :
cvvel_1234 403454663 29.43 3e-30 55.55555555234 1172189
cvell_1444 2342333 30.00 1e-50 34.34584359345 5911
cvell_1444 234230055 23.23 1e-60 32.23445983454 46245
cvell_1444 233493003 23.44 1e-43 35.23595604593 46245
fulltaxa
반환해야합니까 :
1172189, 5943, 1002030, 12345
5911, 11234, 112356, 234, 3456, 44568, 78356
46245, 123, 3432456, 123488976, 23564, 334
46245, 123, 3432456, 123488976, 23564, 334
'filltaxalist'의 모든 줄마다 파일을 한 번 읽습니다. – Blender
'if int == hit'은'if int1 == hit'이어야합니다. –
'filltaxlist'는 매우 큽니까? –