Recursive functions

Nick Perkins nperkins7 at home.com
Thu Jun 28 03:43:58 EDT 2001


non-recursive solutions are usually better in python, but...

you can make a copy of a list by using:
L2 = L1[:]

if you post more of your code and say specifically what it does,
you will get more help.




"Tom Harris" <tomh at optiscan.com> wrote in message
news:mailman.993709842.30168.python-list at python.org...
> Hi,
>
> I am very new to Python, and I am trying to get a recursive function
> working. The problem is that the function modifies one of its arguments,
> which is not a local copy of a variable (local to this stack frame of the
> function, like in call by value in C) but a reference to a variable owned
by
> the function namespace, so changes to the variable are inherited by other
> calls to the same function. I tried copying the argument to a variable in
> the function body, but of course this suffers from the same problem.
>
> This is the idea, but the list just keeps on growing.
>
> def f(aList):
> ...
> aList.append(stuff)
> f(aList)
>
> What is the solution?
>
>  Tom Harris, Software Engineer
>  Optiscan Imaging, 15-17 Normanby Rd, Notting Hill, Melbourne, Vic 3168,
> Australia
>  email tomh at optiscan.com     ph +61 3 9538 3333  fax +61 3 9562 7742
>
> This email may contain confidential information. If you have received this
> email in error, please delete it immediately,and inform us of the mistake
by
> return email. Any form of reproduction, or further dissemination of this
> email is strictly prohibited.
> Also, please note that opinions expressed in this email are those of the
> author, and are not necessarily those of OptiScan Pty Ltd
>
>
>
>





More information about the Python-list mailing list