[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-list
Subject:    Re: Dictionary
From:       ast <none () gmail ! com>
Date:       2019-02-25 16:05:09
Message-ID: 5c741237$0$15176$426a74cc () news ! free ! fr
[Download RAW message or body]

Le 24/02/2019 à 05:21, Himanshu Yadav a écrit  :
> fibs={0:0,1:1}
> def rfib(n):
>        global fibs
>         if not fibs.get(n):
>                  fibs[n]=rfib(n-2)+rfib(n-1)
>          return fibs[n]
> 
> Why it is gives error??
> 

Nothing to do with the malfunction, but you dont need
to define fibs as global since you dont remap "fibs"
in side the function.

As explained by Peter, when n equals 0, not fibs.get(n)
will return True and recursivity goes on with n=-1, -2
until you reach the maximum allowed number of recursion
depth
-- 
https://mail.python.org/mailman/listinfo/python-list

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic