'How to get the previous iteration and current in the same loop python

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.

In order to get the position of the boxes the line length will be used and the box lengths.

So the following cod you see

  • One function fitting the blue box length into blackline

  • One function getting the remain length of the line that has been cut

  • One loop to get the previous remain length added to the next length that need to be fitted for boxes.

enter image description here

enter image description here

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)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source