a little bit of recursion

Skip Montanaro skip at pobox.com
Tue Oct 21 16:01:05 EDT 2003


    Dominik> def rek(N, L):
    Dominik>     N = N + 1
    Dominik>     if N >= 9: return L
    Dominik>     else: return rek(N, L = L.append(N))

In the recursive calls, L is None.  Just pass L as the second arg:

    def rek(N, L):
        N = N + 1
        if N >= 9:
            return L
        L.append(N)
        return rek(N, L)

Skip






More information about the Python-list mailing list