k = [...]d = {}for i in kws: d.setdefault(i,0) for j in kws: if i == j: continue if i in j: d[i] += 1求解如何提供运算速度?
2 回答
杨魅力
TA贡献1811条经验 获得超6个赞
@pykit.runTime
def parse():
p = {}
for k in kws:
for i in k.split():
p.setdefault(i,[]).append(k)
for k in kws:
r = [set(p[i]) for i in k.split()]
r = set.intersection(*r)
d[k] = len(r)-1
kws = [...]
d = {}
d.fromkeys(kws,0)
parse()
研究了一下倒排,速度提高十倍以上
- 2 回答
- 0 关注
- 924 浏览
添加回答
举报
0/150
提交
取消