title: how to split a list into multiple lists with certain ranges?
body: <p>I have a list that needs to be split into 4 separate lists with maximum size of 21 depending on the amount of items in the original list.</p>
  
  <p>The master list can have from 1 to 84 items.</p>
  
  <p>I want the items to start in <code>a</code> and fill up to a maximum of 21 in <code>a, b, c, d</code></p>
  
  <p>I have the following code that can split the items up no problem but I want to know if there is a shorter way to do this.  I am repeating code a lot except the range.</p>
  
  <pre><code>codes = [x for x in range(80)] # range anywhere between 1-84
  
  print(len(codes))
  
  a = []
  b = []
  c = []
  d = []
  
  for i in range(0, 21):
      try:
          a.append(codes[i])
      except IndexError:
          pass
  
  for i in range(21, 42):
      try:
          b.append(codes[i])
      except IndexError:
          pass
  
  for i in range(42, 63):
      try:
          c.append(codes[i])
      except IndexError:
          pass
  
  for i in range(63, 84):
      try:
          d.append(codes[i])
      except IndexError:
          pass
  
  print(len(a), len(b), len(c), len(d))
  print(a)
  print(b)
  print(c)
  print(d)
  </code></pre>
  
  <p>Before that I had this code that works great for the whole 84 items as the order is not important..</p>
  
  <pre><code>    a = []
      b = []
      c = []
      d = []
  
      for a1, b1, c1, d1 in zip(*[iter(codes)]*4):
          a.append(a1)
          b.append(b1)
          c.append(c1)
          d.append(d1)
  </code></pre>
  
  <p>However if i have say 4 items, it will add 1 to each</p>
  
  <pre><code>a = [0]
  b = [1]
  c = [2]
  d = [3]
  </code></pre>
  
  <p>What I would like to obtain is</p>
  
  <pre><code>a = [0, 1, 2, 3]
  b = []
  c = []
  d = []
  </code></pre>