<p>使用一些基本的列表理解:</p>
<pre><code>lst = ['>ENST00000262144 cds:known chromosome:GRCh37:16:74907468:75019046:-1 gene:ENSG00000103091 gene_biotype:protein_coding transcript_biotype:protein_coding', '>ENST00000446813 cds:known chromosome:GRCh37:7:72349936:72419009:1 gene:ENSG00000196313 gene_biotype:protein_coding transcript_biotype:protein_coding']
res = [el[5:] for s in lst for el in s.split() if el.startswith('gene:')]
</code></pre>
<p>如果您更喜欢使用常规for循环来执行此操作,请使用以下命令:</p>
<pre><code>lst = ['>ENST00000262144 cds:known chromosome:GRCh37:16:74907468:75019046:-1 gene:ENSG00000103091 gene_biotype:protein_coding transcript_biotype:protein_coding', '>ENST00000446813 cds:known chromosome:GRCh37:7:72349936:72419009:1 gene:ENSG00000196313 gene_biotype:protein_coding transcript_biotype:protein_coding']
res = []
for el in lst: # for each string in your list
l = el.split() # create a second list, of split strings
for s in l: # for each string in the 'split strings' list
if s.startswith('gene:'): # if the string starts with 'gene:' we know we have match
res.append(s[5:]) # so skip the 'gene:' part of the string, and append the rest to a list
</code></pre>