title: Better way to get sublist in python
body: <p>I am working on the following problem:
  This function returns a list of all possible sublists in L of length n without skipping elements in L. The sublists in the returned list should be ordered in the way they appear in L, with those sublists starting from a smaller index being at the front of the list.</p>
  
  <p><code>Example 1, if L = [10, 4, 6, 8, 3, 4, 5, 7, 7, 2] and n = 4</code> then your function should return the list <code>[[10, 4, 6, 8], [4, 6, 8, 3], [6, 8, 3, 4], [8, 3, 4, 5], [3, 4, 5, 7], [4, 5, 7, 7], [5, 7, 7, 2]]</code></p>
  
  <p>My solution works but how can I make it shorter? What is a better way to do this?</p>
  
  <pre><code>def getSublists(L, n):
  
      newN = n
      myList = []
      for i in range(len(L)):
          orginalLen = L[i:n]
          if(len(orginalLen) == n):
              myList.append(L[i:n])
              n = n + 1
          else:
              myList.append(L[i:n])
              n = n + 1
      if(newN == 1):
          print(myList)
      else:
          print(myList[:len(myList)-(n-1)])
  getSublists([10, 4, 6, 8, 3, 4, 5, 7, 7, 2],4)
  
  getSublists([1], 1)
  
  getSublists([0, 0, 0, 0, 0], 2)
  
  
  
  OUTPUT
  [[10, 4, 6, 8], [4, 6, 8, 3], [6, 8, 3, 4], [8, 3, 4, 5], [3, 4, 5, 7], [4, 5, 7, 7], [5, 7, 7, 2]]
  [[1]]
  [[0, 0], [0, 0], [0, 0], [0, 0]]
  </code></pre>