title: Clump Finding in DNA sequence
body: <p>I am trying to understand a short code for solving clump finding in DNA sequence. The question is</p>
  <blockquote>
  <p>Given integers L and t, a string Pattern forms an (L, t)-clump inside a (larger) string Genome if there is an interval of Genome of length L in which Pattern appears at least t times.</p>
  <p>For example, TGCA forms a (25,3)-clump in the following Genome: <code>gatcagcataagggtcccTGCAaTGCAtgacaagccTGCAgttgttttac</code>.</p>
  <p>Clump Finding Problem</p>
  <p>Find patterns forming clumps in a string.</p>
  <p>Given: A string Genome, and integers k, L, and t.</p>
  <p>Return: All distinct k-mers forming (L, t)-clumps in Genome.</p>
  </blockquote>
  <p>And the code is below:</p>
  <pre><code>from collections import defaultdict
  
  def search(inseq, k, L, t):
      lookup = defaultdict(list)
      result = set()
      
      for cursor in range(len(inseq) - k + 1):
          seg = inseq[cursor:cursor + k]
          
          # remove prior positions of the same segment
          # if they are more than L distance far
          while lookup[seg] and cursor + k - lookup[seg][0] &gt; L:
              lookup[seg].pop(0)
          
          lookup[seg].append(cursor)
          if len(lookup[seg]) == t:
              result.add(seg)
      
      return result
  </code></pre>
  <p>Here are my questions,</p>
  <p>(1) What is the purpose of using defaultdict instead of dict?</p>
  <p>(2) What is a lookup[seg]? Is it the starting position of the k-mer clump?</p>