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 ?
#4
(Mar-15-2019, 12:11 AM)micseydel Wrote: You're using recursion. When you have recursion, you have two situations: a "base case" (where you don't recurse) and a recursive case. The error you're encountering is incredibly common when the base case isn't solid. I suggest you not just use Yoriz' code, but rather you walk through your own code and then his in order to understand what's happening.

Also, this looks like homework, which often has weird requirements, but I wouldn't use recursion for what you're trying to do there.

Thank you for your reply. I'm still trying to understand some basic python knowledge. Your answer is very helpful.
I move forward a little bit and came up with another weird problem as below.

def ChangeList(itr, K =[0]):
    if itr < 10:
        K.append(1)
        itr += 1
        return ChangeList(K, itr)

    else:

        return K

for i in range(5):
    print (ChangeList(i, K = [0]))
I was trying to using recursion in a for loop, but it did work as I expected. Could you please show me the right way to do it?
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, 03:03 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Pyinstaller Maximum recursion bug scales11 8 11,154 Nov-10-2023, 10:26 PM
Last Post: SuzanneKH09
  Max recursion depth.... Error MeloB 2 1,946 Feb-16-2022, 05:21 PM
Last Post: MeloB
  Time Limit Exceeded error loves 5 3,195 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,811 Aug-02-2020, 02:21 PM
Last Post: deanhystad
  Requesting help with my implementation of depth-first search tigerfuchs 6 2,654 Sep-26-2019, 05:47 AM
Last Post: perfringo
  fibonacci ***Time limit exceeded*** frequency 18 10,395 Nov-29-2018, 09:03 PM
Last Post: frequency
  'Time Limit Exceeded' Problem bkpee3 2 5,485 Nov-14-2018, 03:51 AM
Last Post: bkpee3
  Why I get RecursionError on very small amount of data? wavic 3 3,974 Aug-05-2018, 04:55 PM
Last Post: micseydel
  variable loop depth Skaperen 5 4,415 Jul-18-2018, 02:48 AM
Last Post: Skaperen
  maximum recursion depth exceeded saba_keon 3 7,488 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