【发布时间】:2015-04-30 08:03:42
【问题描述】:
我正在搜索分层字典,我必须将内容放入名为“内容”的变量中:
def look_through(d, s):
r = []
content = readFile(d["path"])
if s in content:
if "phrase" not in d:
d["phrase"] = [s]
else:
d["phrase"].append(s)
r.append({"content": content, "phrase": d["phrase"], "name": d["name"]})
for b in d["decendent"] or []:
r += look_through(b, s)
return r
但“内容”应该是文本的摘录,而不是完整的内容,即搜索词组后面的几个词和前面的几个词。
例如:
短语:“寻找”
内容:……她在寻找他……
如何裁剪函数中的内容以达到此结果? 谢谢!
【问题讨论】:
标签: python django string search