title: How to divide a list into chunks of alternating sizes in Python?
body: <p>I need to divide a string into chunks of unequal sizes, that is ,if in a for loop i meets a certain condition then the chunk should be of specific length otherwise of different length. Basically I need to create a 2d array(list) where I know the number of rows but don't know the number of columns as the length of string is unknown. I tried various methods on googling. Here is one I tried on own.</p>
  <pre><code>    a = [1,2,3,4,5,6,7,8]
  b = []
  c=[]
  def divide_chunks(l): 
        
      # looping till length l 
      for i in range(0, len(l)):
          j = 0
          if(i%2==0):
             while(j&lt;4 and i&lt;=len(l)):
                 b.append(l.pop())
                 i = i+1
          else:
                while(j&lt;2 and i&lt;=len(l)):
                 b.append(l.pop())
                 i = i+1
          c.append(b)    
  </code></pre>
  <p>The problem I am facing is that the numbers or lets say words in case of string are getting overlapped in each chunk. For example one of the output is</p>
  <blockquote>
  <p>[[8, 7, 6, 5, 4, 3, 2], [8, 7, 6, 5, 4, 3, 2], [8, 7, 6, 5, 4, 3, 2], [8, 7, 6, 5, 4, 3, 2], [8, 7, 6, 5, 4, 3, 2], [8, 7, 6, 5, 4, 3, 2], [8, 7, 6, 5, 4, 3, 2], [8, 7, 6, 5, 4, 3, 2]]</p>
  </blockquote>
  <p>So I want to achieve something like if string is markisgoodboy. Then for first row it will take &quot;mark&quot; second row &quot;is&quot; and third row &quot;good&quot; and fourth row &quot;bo&quot; and last row &quot;y&quot;. Please take note that it is row wise. The length of rows will be supplied as an argument for every method call. How to solve it ?
  Thanks :)</p>