title: Automatically writing headers using csv python
body: <p>I'm trying to write a motif finding function which takes amino acid fasta as an input and outputs an motifs in the excel file.</p>
  
  <p>My desired output looks like this..</p>
  
  <pre><code>SeqName     M1      Hits    M2          Hits
  Seq1        MN[A-Z] 3       V[A-Z]R[ML] 2
  Seq2        MN[A-Z] 0       V[A-Z]R[ML] 5
  Seq3        MN[A-Z] 1       V[A-Z]R[ML] 0
  </code></pre>
  
  <p>I've been trying to automatically generate the headers since the motifs that I'm searching for is over 2. (In the example above , there are only two(M1 and M2)).</p>
  
  <p>The code that Ive been working on looks like this..</p>
  
  <pre><code>import re
  from Bio import SeqIO
  import csv
  import collections
  
  def SearchMotif(f1, motif, f2="motifs1.xls"):
      with open(f1, 'r') as fin, open(f2,'wb') as fout:
          writer = csv.writer(fout, delimiter = '\t')
  
          writer.writerow(['M%s'%(i+1)for i in range(0,len(motif),1)])
          writer.writerow(['Hits' for i in range(0,len(motif),1)])
  </code></pre>
  
  <p>And this generates </p>
  
  <pre><code>M1      M2
  Hits    Hits
  </code></pre>
  
  <p>Is there any way that I could make my header rows looks like my desired output?</p>
  
  <p>Hits are static but M1 will be increased by length of motifs. So if I have 5 different types of motifs to search, it will be like..</p>
  
  <pre><code>SeqName    M1    Hits    M2    Hits    M3    Hits    M4    Hits    M5    Hits
  </code></pre>