How to obtain desired output? I am working on a project using the following command within nano:
from Bio import SeqIO
import sys
import re 


    fasta_file = (sys.argv[1])
    for myfile in SeqIO.parse(fasta_file, &quot;fasta&quot;):
      if len(myfile) &gt; 250:
       gene_id = myfile.id
       mylist = re.match(r&quot;H149xcV_\w+_\w+_\w+&quot;, gene_id)
       print (&quot;&gt;&quot;+mylist.group(0))   # edited from list to mylist

and its providing with the following outout:
&gt;H149xcV_Fge342_r3_h2_d1
&gt;H149xcV_bTr423_r3_h2_d1
&gt;H149xcV_kN893_r3_h2_d1
&gt;H149xcV_DNp021_r3_h2_d1
&gt;H149xcV_JEP3324_r3_h2_d1
&gt;H149xcV_SRt424234_r3_h2_d1

How can I change my command so that it provides me with the desired format and only the UNIQUE gene id's:
&gt;H149xcV_Fge342_r3_h2
&gt;H149xcV_bTr423_r3_h2
&gt;H149xcV_kN893_r3_h2
&gt;H149xcV_DNp021_r3_h2
&gt;H149xcV_JEP3324_r3_h2
&gt;H149xcV_SRt424234_r3_h2
its easy replace match with sub but please stop using list as a variable ... mylist is fine.
This might work
   mylist = re.sub(r'H149xcV_\w+_\w+_\w+', gene_id)

otherwise
myregex = re.compile('_\w+\s+.*') 
fastaid = myregex.sub('', myfile)

OR from @MaximilianPress
myregex2 = re.compile('_\w+\n') # or myregex2 = re.compile('_\w+$')
fastaid2 = myregex.sub('\n', myfile) # or fasaid2 = myregex.sub('', myfile)

The above will work ... As with all my code I never proof it ..