title: How to get the previous iteration and current in the same loop python
body: <p>The problems follows
  There are lines these lines needs to cut in certain positions and boxes need to be fit along the line taking into account  there they need to be cut.</p>
  <p>In order to get the position of the boxes the line length will be used and the box lengths.</p>
  <p>So the following cod you see</p>
  <ul>
  <li><p>One function fitting the blue box length into blackline</p>
  </li>
  <li><p>One function getting the remain length of the line that has been cut</p>
  </li>
  <li><p>One loop to get the previous remain length added to the next length that need to be fitted for boxes.</p>
  </li>
  </ul>
  <p><a href="https://i.stack.imgur.com/bNSdp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bNSdp.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/Uwjrd.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Uwjrd.jpg" alt="enter image description here" /></a></p>
  <pre><code>cLengths, sizes = IN
  
  def fitLengths(remainder, sizes):
      lengths = []
      _fn1 = partial(le, b=remainder)
      validSizes = filter(_fn1, sizes)
      while validSizes:
          s1 = max(validSizes)
          lengths.extend(repeat(s1, remainder // s1) )
          remainder = remainder % s1
          _fn1 = partial(le, b=remainder)
          validSizes = filter(_fn1, sizes)
      return lengths
  
  def fitRE(remainder, sizes):
  
      _fn1 = partial(le, b=remainder)
      validSizes = filter(_fn1, sizes)
      while validSizes:
          s1 = max(validSizes)
  
          remainder = remainder % s1
          _fn1 = partial(le, b=remainder)
          validSizes = filter(_fn1, sizes)
      return remainder
  
  
  test=[]
  for i in cLengths:
      itest=[]
      test.append(itest)
      for j in i:
          b=fitRE(j,sizes)
          a=fitLengths(((j+1)+b),sizes)
          itest.append(a)
  </code></pre>