擅长:python、mysql、java
<p>也许是这样的:</p>
<pre><code>def get_sub_strings(s):
words = s.split()
for i in xrange(1, len(words)+1): #reverse the order here
for n in xrange(0, len(words)+1-i):
yield ' '.join(words[n:n+i])
...
>>> out = []
>>> for word in c:
for sub in get_sub_strings(word.lower()):
for s in isl:
if sub in s.lower():
out.append(sub)
...
>>> out
['john', 'query', '989877', 'query 989877', 'tamm']
</code></pre>
<p>如果只想存储最大的匹配项,则需要以相反的顺序生成子字符串,并在^{<cd1>中找到匹配项时立即中断:</p>
^{pr2}$