title: Finding the recurring pattern
body: <p>Let's say I have a number with a recurring pattern, i.e. there exists a string of digits that repeat themselves in order to make the number in question. For example, such a number might be <code>1234123412341234</code>, created by repeating the digits <code>1234</code>.<br>
  What I would like to do, is find the pattern that repeats itself to create the number. Therefore, given <code>1234123412341234</code>, I would like to compute <code>1234</code> (and maybe <code>4</code>, to indicate that <code>1234</code> is repeated 4 times to create <code>1234123412341234</code>)</p>
  
  <p>I know that I could do this:</p>
  
  <pre><code>def findPattern(num):
      num = str(num)
      for i in range(len(num)):
          patt = num[:i]
          if (len(num)/len(patt))%1:
              continue
          if pat*(len(num)//len(patt)):
              return patt, len(num)//len(patt)
  </code></pre>
  
  <p>However, this seems a little too hacky. I figured I could use <code>itertools.cycle</code> to compare two cycles for equality, which doesn't really pan out:</p>
  
  <pre><code>In [25]: c1 = itertools.cycle(list(range(4)))
  
  In [26]: c2 = itertools.cycle(list(range(4)))
  
  In [27]: c1==c2
  Out[27]: False
  </code></pre>
  
  <p>Is there a better way to compute this? (I'd be open to a regex, but I have no idea how to apply it there, which is why I didn't include it in my attempts)</p>
  
  <p><strong>EDIT</strong>:</p>
  
  <ol>
  <li>I don't necessarily know that the number has a repeating pattern, so I have to return <code>None</code> if there isn't one. </li>
  <li>Right now, I'm only concerned with detecting numbers/strings that are made up entirely of a repeating pattern. However, later on, I'll likely also be interested in finding patterns that start after a few characters:</li>
  </ol>
  
  <blockquote>
    <p>magic_function(78961234123412341234)</p>
  </blockquote>
  
  <p>would return <code>1234</code> as the pattern, <code>4</code> as the number of times it is repeated, and <code>4</code> as the first index in the input where the pattern first presents itself</p>