title: Generate sliding window of iterable with length n by step m
body: <pre><code>def windows(iterable,n,m=1):
      x = iter(iterable)
      l = []
      y = next(x)
      for i in range(n):
          l.append(y)
          y = next(x)
      yield l
  
      while x:
          for i in range(m):
              l.pop(0)
          for i in range(m):
              l.append(y)
              y = next(x)
          yield l
  </code></pre>
  
  <p>I need to write a windows generator takes an iterable and two ints (call them n and m; with m’s default value 1) as parameters: it produces lists of n values: the first list contains the first n values; every subsequent list drops the first m from the previous list and adds the next m values from the iterable, until there are fewer than n values to put in the returned list.</p>
  
  <p>for instance:</p>
  
  <pre><code>for i in windows('abcdefghijk', 4,2):
      print(i,end='')
  </code></pre>
  
  <p>prints <code>['a','b','c','d'] ['c','d','e','f'] ['e','f','g','h'] ['g','h','i','j']</code>.</p>
  
  <p>when I call the above function, my code prints</p>
  
  <pre><code>[['i', 'j', 'k'], ['i', 'j', 'k'], ['i', 'j', 'k'], ['i', 'j', 'k']]
  </code></pre>
  
  <p>I cannot figure out the problem. can someone help me to fix it? Thanks in advance. </p>