title: Python: Finding length of the repeating sequence of numbers in a string of floats
body: <p>I am trying to write a function which takes in a list of floats and determines whether or not there is a repeating sequence of number within that list. If there is a repeating sequence then it counts the numbers in that sequence.</p>
  
  <p>These examples are what I want my function to do</p>
  
  <p>Example 1:</p>
  
  <pre><code>function = '1.0 8.0 4.0 2.0 1.0 8.0 4.0 2.0 1.0 8.0 4.0 2.0 1.0 8.0'
  result = find_repeating_sequence(function)
  # repeating sequence = 1.0, 8.0, 4.0, 2.0
  # so result should equal 4 in this case
  </code></pre>
  
  <p>Example 2:</p>
  
  <pre><code>function = '1.0 8.0 4.0 1.0 2.0 1.0 8.0 4.0 1.0 2.0 1.0 8.0'
  result = find_repeating_sequence(function)
  # repeating sequence = 1.0, 8.0, 4.0, 1.0, 2.0
  # so result should equal 5 in this case
  </code></pre>
  
  <p>Example 3:</p>
  
  <pre><code>function = '1.0 8.0 4.0 2.0 1.0 7.0 6.0 3.0 2.0 5.0 9.0'
  result = find_repeating_sequence(function)
  # repeating sequence doesn't exist
  # so result should equal None in this case
  </code></pre>
  
  <p>Example 4:</p>
  
  <pre><code>function = '1.0 11.0 1.0 11.0 1.0 11.0 1.0 11.0 1.0 11.0 1.0 11.0 1.0 11.0 1.0 11.0'
  result = find_repeating_sequence(function)
  # repeating sequence = 1.0, 11.0
  # so result should equal 2 in this case
  </code></pre>
  
  <p>So far what I have got is:</p>
  
  <pre><code>def find_repeating_sequence(function):
          regex = re.compile(r'(.+ .+)( \1)+')
          match = regex.search(function)
          result = match
  
         if result == None:
              print "There was no repeating sequence found!"
          else:
              print "Repeating sequence found!"
              print match.group(1)
              result = match.group(1)
  
         return result
  </code></pre>
  
  <p>This works for all examples in the sense that <code>match.group(1)</code> gives the repeating sequence. However for some reason <code>len(match.group(1))</code> does not return the correct number. </p>
  
  <p>Like for Example 1:</p>
  
  <p><code>print match.group(1)</code> gives <code>1.0 8.0 4.0 2.0</code></p>
  
  <p>But <code>print len(match.group(1))</code> gives <code>15</code></p>
  
  <p>Also it does not return the correct value for Example 4:
  <code>print match.group(1)</code> gives <code>1.0 11.0 1.0 11.0 1.0 11.0 1.0 11.0</code></p>
  
  <p>And <code>print len(match.group(1))</code> gives <code>35</code></p>
  
  <p>What am I doing wrong?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Thanks to one of the answers below I have solved the <code>print len(match.group(1))</code> issue by using len(match.group(1).split())</p>
  
  <p>However for some reason if
  <code>function = 1.0 2.0 4.0 8.0 1.0 2.0 4.0 8.0 1.0 2.0 4.0 8.0 1.0 2.0 4.0 8.0</code>
  <code>print match.group(1)</code> gives <code>1.0 2.0 4.0 8.0 1.0 2.0 4.0 8.0</code>
  and not <code>1.0 2.0 4.0 8.0</code></p>