a little bit of recursion

rzed Dick.Zantow at lexisnexis.com
Tue Oct 21 15:59:39 EDT 2003


Dominik Kaspar wrote:
> I'm trying to write a quite big recursive function, but the baseline
> is the following:
>
> def rek(N, L):
>     N = N + 1
>     if N >= 9: return L
>     else: return rek(N, L = L.append(N))
>
> print rek(0, [])
>
> Why isn't this working?
> In my opinion it should return [1, 2, ..., 9]
>
> Thanks for any answers.


One problem is that L = L.append(N) does not have the effect you want.
Try it on its own.
Another is that it won't return [1,2,...,9] even when that is
corrected.








More information about the Python-list mailing list