Python Forum
RecursionError: maximum recursion depth exceeded in comparison ?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
RecursionError: maximum recursion depth exceeded in comparison ?
#8
(Mar-15-2019, 01:22 PM)ichabod801 Wrote: You put your parameters in the wrong order on line 5.

Thanks! But in the scripts below. I meet a similar problem. The function works fine by its own, but will have an error in the "for loop". I don't know where goes wrong. The orders are correct. Could you help me? Thanks again!

# This is a script to generates layouts for rectangles. The result is expected to be a list of X,Y values.

# Lx and Ly are the rectangles' X, Y value lists. Different levels represents different categories.

# xgap and ygap are the gaps between rectangles

# H is the list of heights for different categories.

Lx = [[38.297,34.641,25.81,10.33,54.26],[48.99 ,25.82 ,36.51 ,40 ,51.64]]
Ly = [[28.72,25.98,19.36,16.54,41.35],[36.74 ,19.36 ,27.39 ,30 ,38.73]]

xgap = 56
ygap = 19
H = [73.35,111.37]



# itn is the judge for if each rectangle should stay in the same column or start a new column.
# itn2 is the counter.


def MoveAcorHeight(lx, ly, xgap, ygap, H, itn = None, K = [(0,0)], itn2=0):
    #Set a special condition for one element lists.
    if len(lx) == 1:
        return K

    #If the list has more than one elements reset the counter.
    if len(lx) > 1 and itn2 == 0:
        itn = ly[0] + ygap + ly[itn2+1]
        itn2 +=1
        return MoveAcorHeight(lx, ly, xgap, ygap, H, itn, K, itn2)


    #If the judge (itn) > H, start a new column.
    elif 0 < itn2 < len(lx) - 1 and itn > H :
        PrebsX = {}
        for i in K:
            PrebsX[i[0]] = []
        for i in range(len(K)):
            PrebsX[K[i][0]].append(lx[i])

        preJ = []
        for i in PrebsX:
            preJ.append(max(PrebsX[i]))

        J = sum(preJ) + len(preJ) * xgap


        K.append((J, 0))

        PrebsY = {}
        for i in K:
            PrebsY[i[0]] = []
        for i in range(len(K)):
            PrebsY[K[i][0]].append(ly[i])

        preI = PrebsY[K[-1][0]]
        I = sum(preI) + len(preI) * ygap
        itn2 += 1

        itn = I + ly[itn2] + ygap

        return MoveAcorHeight(lx, ly, xgap, ygap, H, itn, K, itn2)

    # To deal with the last element.
    elif itn2 == len(lx) - 1 and itn > H:
        PrebsX = {}
        for i in K:
            PrebsX[i[0]] = []
        for i in range(len(K)):
            PrebsX[K[i][0]].append(lx[i])

        preJ = []
        for i in PrebsX:
            preJ.append(max(PrebsX[i]))

        J = sum(preJ) + len(preJ) * xgap

        K.append((J, 0))
        return K



    # If the judge (itn) <= H, rectangle stay in the same column.
    elif 0< itn2 < len(lx) - 1 and itn <= H:

        PrebsY = {}
        for i in K:
            PrebsY[i[0]] = []
        for i in range(len(K)):
            PrebsY[K[i][0]].append(ly[i])

        preI = PrebsY[K[-1][0]]
        I = sum(preI) + len(preI) * ygap
        K.append((K[itn2 - 1][0], -I))


        itn2 += 1

        itn = I + ly[itn2 - 1] + ygap + ly[itn2]


        return MoveAcorHeight(lx, ly, xgap, ygap, H, itn, K, itn2)

    # To deal with the last element.
    elif itn2 == len(lx) - 1 and itn <= H:
        PrebsY = {}
        for i in K:
            PrebsY[i[0]] = []
        for i in range(len(K)):
            PrebsY[K[i][0]].append(ly[i])

        preI = PrebsY[K[-1][0]]
        I = sum(preI) + len(preI) * ygap
        K.append((K[itn2 - 1][0], -I))

        return K



L = []

### The script works fine when deal with one list, (L.append(MoveAcorHeight(Lx[0], Ly[0], xgap, ygap, H[0]))). But will have a "out of range" warning while running in the for loop.

for i in range(len(Lx)):
    L.append(MoveAcorHeight(Lx[i], Ly[i], xgap, ygap, H[i]))


print (L)
Reply


Messages In This Thread
RE: Iteration Question - by Yoriz - Mar-14-2019, 10:35 PM
RE: RecursionError: maximum recursion depth exceeded in comparison ? - by leoahum - Mar-15-2019, 07:35 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Pyinstaller Maximum recursion bug scales11 8 11,113 Nov-10-2023, 10:26 PM
Last Post: SuzanneKH09
  Max recursion depth.... Error MeloB 2 1,932 Feb-16-2022, 05:21 PM
Last Post: MeloB
  Time Limit Exceeded error loves 5 3,183 Dec-03-2020, 07:15 AM
Last Post: Sofia_Grace
Bug maximum recursion depth exceeded while calling a Python object error in python3 Prezess 4 3,794 Aug-02-2020, 02:21 PM
Last Post: deanhystad
  Requesting help with my implementation of depth-first search tigerfuchs 6 2,633 Sep-26-2019, 05:47 AM
Last Post: perfringo
  fibonacci ***Time limit exceeded*** frequency 18 10,332 Nov-29-2018, 09:03 PM
Last Post: frequency
  'Time Limit Exceeded' Problem bkpee3 2 5,476 Nov-14-2018, 03:51 AM
Last Post: bkpee3
  Why I get RecursionError on very small amount of data? wavic 3 3,968 Aug-05-2018, 04:55 PM
Last Post: micseydel
  variable loop depth Skaperen 5 4,405 Jul-18-2018, 02:48 AM
Last Post: Skaperen
  maximum recursion depth exceeded saba_keon 3 7,472 Apr-08-2018, 07:30 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020