title: Finding the Period of a Pattern in a List
body: <p>I'm relatively new to coding but I saw a great <a href="https://www.youtube.com/watch?v=acTrvMlpuxA" rel="nofollow noreferrer">episode of Numberphile</a> where they use a particular repeating pattern of the modulus of the Fibonacci sequence to assign tones to the resulting number. What a great little experiment to test my knowledge out on!</p>
  
  <p>So I was able to create a simple loop to create a list of the Fibonacci sequence and another function to calculate the remainder of the generated sequence after dividing by n. But finding the period of the pattern in that modulus list is proving to be difficult.</p>
  
  <p>Here's what I have so far:</p>
  
  <pre><code>#Fibonacci.py
  #Basic terms
  fiblist = list()
  inp = "&gt; "
  n=None
  
  #Calculates the FIbonacci sequence
  def fib(n):
      a,b = 0,1
      while True:
          try:
              print "How many terms? "
              n = int(raw_input(inp))
              if n &lt;= 0:
                  print "Please enter a positive integer."
                  continue
              else:
                  for i in range(0,n):
                      a,b = b, a + b
                      fiblist.append(a)
                  break
          except ValueError:
              print "Please enter a positive integer, not a letter or symbol"
              continue    
      return fiblist
  
  #Calculates the modulo of each integer in fiblist
  def modulo(n):  
      print """
  Do you want to find the modulo?
  1. Yes
  2. No"""
      choice = raw_input(inp)
      if choice =="1":
          modlist = list()
          print "What modulo do you want to use?"
          modx = int(raw_input(inp))
          modlist = [x % modx for x in fiblist]
          print modlist
          print "The period of the pattern is ", principal_period(modlist)
          print "Goodbye!"
      else: 
          print "Goodbye!"
  
  #Calculates the period of the modulo pattern of the Fibonacci sequence
  def principal_period(modlist):
      a = str(modlist)
      i = (a+a).find(a, 1, -1)
      return None if i == -1 else n[:i]
  
  print fib(n)
  modulo(n)
  </code></pre>
  
  <p>The part that's failing me is </p>
  
  <pre><code>def principal_period(modlist):
      a = str(modlist)
      i = (a+a).find(a, 1, -1)
      return None if i == -1 else n[:i]
  </code></pre>
  
  <p>which always returns "None" I got this from the thread <a href="https://stackoverflow.com/questions/29481088/how-can-i-tell-if-a-string-repeats-itself-in-python/29482936#29482936">over here</a> regarding the answer. I honestly do not understand this answer very well and it is not giving me the desired result.</p>
  
  <p>Do you have any suggestions for calculating the period of a repeating pattern in a given list?</p>