Добрый день!
Есть текстовый файл с предложениями, размером 10Гб
Подскажите, как реализовать скоростную выборку по регулярным выражениям ?
key_filter = [re.compile(x.decode("utf-8"), re.I) for x in read_lines(key_filter)]
for line in open(src, "r"):
try:
mline = line.decode("utf-8").lower().strip(" \r\n")
if mline not in keywords:
if any([x.match(mline) for x in key_filter]):
keywords.append(mline)
f_dst.write(line)
f_dst.flush()
count +=1
print count
except UnicodeError:
f_dst_err.write(line)
f_dst_err.flush()
import re
import time
rr=re.compile("mama.+$")
t0=time.clock()
s=open(r"Arh3b.dat","rb").read()
res=rr.findall(s)
t1=time.clock()
print t1-t0