removing elements from a list of genes
<p>I have a list like this:</p>

<pre><code>['&gt;ENST00000262144 cds:known chromosome:GRCh37:16:74907468:75019046:-1 gene:ENSG00000103091 gene_biotype:protein_coding transcript_biotype:protein_coding', 
 '&gt;ENST00000446813 cds:known chromosome:GRCh37:7:72349936:72419009:1 gene:ENSG00000196313 gene_biotype:protein_coding transcript_biotype:protein_coding']
</code></pre>

<p>I want to make a new list with the same dimension and order but in the new list I will keep only gene id. the results would be like this:</p>

<pre><code>['ENSG00000103091', 'ENSG00000196313']
</code></pre>

<p>I am using python. do you guys know how to do that? thanks</p>

<p>This is by no means the most Pythonic way to achieve this but it should do what you want.</p>

<pre><code>l = [
    '&gt;ENST00000262144 cds:known chromosome:GRCh37:16:74907468:75019046:-1 gene:ENSG00000103091 gene_biotype:protein_coding transcript_biotype:protein_coding',
    '&gt;ENST00000446813 cds:known chromosome:GRCh37:7:72349936:72419009:1 gene:ENSG00000196313 gene_biotype:protein_coding transcript_biotype:protein_coding'
]
genes = []
for e in l:
    e = e.split('gene:')
    gene = ''
    for c in e[1]:
        if c != ' ':
            gene += c
        else:
            break
    genes.append(gene)

print(genes)
</code></pre>

<p>Loop through the elements in the list then split them on <code>gene:</code> after that append all the chars to a string and add it to an array.</p>

python