title: list of sub-lists provided number of sublists and its elements
body: <pre><code>def listOfLists(ntimes,lines,list_val):
      a = []
      i = 0
      j = 0
  
      if ntimes &gt;= lines:
          inner_loop = ntimes
          outer_loop = lines
      else:
          inner_loop = lines
          outer_loop = ntimes
  
      while i &lt; outer_loop:
          while j &lt; inner_loop+i:
              if (j*inner_loop-i &lt; len(list_val)):
                  a.append(list_val[j*inner_loop-i])
                  j=j+1
  
              else:
                  j=1
                  a.append(list_val[j*inner_loop-i])
                  break
  
          j = i+1
          i = i+1
          print a
      y = [a[x:x+ntimes] for x in range(0, len(a), ntimes)]
      print y
  </code></pre>
  
  <p>What I'd like is a list with sublists whose number of elements is ntimes and lines is the number of sublists. If input is like <code>listOfLists(2,3,[1,2,3,4,5,6])</code> then output should be:</p>
  
  <pre><code>[[1,4],[2,5],[3,6]]
  </code></pre>
  
  <p>I'm currently getting:</p>
  
  <pre><code>[[1, 4], [4, 3], [6, 3]]
  </code></pre>
  
  <p>How can I fix my code to achieve this?</p>