title: Counting consecutive numbers in a list
body: <p>I couldn't find a question that was similar enough to mine to where I could develop a satisfactory answer.</p>
  
  <p>I'm pretty new to Python (3.4.3). I am trying to add elements to an output list using a for loop by comparing each element of an input list to the next element in it.</p>
  
  <p>Here is my code so far:</p>
  
  <pre><code>random_list=[1,4,5,6,7,9,19,21,22,23,24]
  
  def count_consec(random_list):
      count=1
      consec_list=[]
      for i in listrand:
          if listrand[i] == listrand[i+1]+1:
              count+=1
          else:
              list.append(count)
      return consec_list
  </code></pre>
  
  <p>Basically, I want to add to <code>consec_list[]</code> values that represent how the length of consecutive blocks of numbers in <code>random_list[]</code>.</p>
  
  <p>I expect my output in this case to look like this:</p>
  
  <pre><code>[1,4,1,1,4]
  </code></pre>
  
  <p>As in, there is one singular number, followed by 4 consecutive numbers, followed by one singular number, followed by one singular number, followed by 4 consecutive numbers.</p>
  
  <p>I tried many different ways and I have gotten the function to build a list, but all the elements are 1s.</p>