擅长:python、mysql、java
<p>如果您只想在“根字符串”第一次出现的两边各有4个单词,可以使用:</p>
<pre><code>root = 'mtnr1a'
s = 'lack of association between the promoter polymorphism of the mtnr1a gene and adolescent idiopathic scoliosis'
s_list = s.split(' ')
ix = s_list.index(root)
out = ' '.join(s_list[-4+ix:ix+5])
out
# returns:
'promoter polymorphism of the mtnr1a gene and adolescent idiopathic'
</code></pre>