[EMAIL PROTECTED] wrote:
> hi, i have the following recursive function (simplified to demonstrate
> the problem):
>
> >>> def reTest(bool):
> ... result = []
> ... if not bool:
> ... reTest(True)
> ... else:
> ... print "YAHHH"
> ... result = ["should be the onl
[EMAIL PROTECTED] wrote:
> hi, i have the following recursive function (simplified to demonstrate
> the problem):
>
>
def reTest(bool):
>
> ... result = []
> ... if not bool:
> ... reTest(True)
> ... else:
> ... print "YAHHH"
> ... result = ["should be the
[EMAIL PROTECTED] writes:
> hi, i have the following recursive function (simplified to demonstrate
> the problem):
def reTest(bool):
> ... result = []
> ... if not bool:
> ... reTest(True)
> ... else:
> ... print "YAHHH"
> ... result = ["should be the only t
[EMAIL PROTECTED] wrote:
> ... if not bool:
> ... reTest(True)
> I don't understand why results are returned twice? is there something
> special i missed about recursive functions?
Yes, although it is not clear *what* it is that you are missing.
Here is my guess: you fail to see that
On Wed, 28 Dec 2005 16:05:30 -0800, randomtalk wrote:
> the final returned value is: []
>
> the two values printed is (note i only have one print statement
> printing "print result",. however, in the actualality, it's printed
> twice):
> printing result:
> ['should be the only thing returned']
>
ah, result = reTest(True) works, thanks alot :D
--
http://mail.python.org/mailman/listinfo/python-list
On Wed, 28 Dec 2005 15:25:30 -0800, randomtalk wrote:
> hi, i have the following recursive function (simplified to demonstrate
> the problem):
>
def reTest(bool):
> ... result = []
> ... if not bool:
> ... reTest(True)
> ... else:
> ... print "YAHHH"
> ...
You have two calls to reTest and so reTest needs to return twice. One
return is from the reTest(True) call back to reTest(False). The second
return is from reTest(False) back to the prompt.
What were you expecting to happen?
--
http://mail.python.org/mailman/listinfo/python-list
On 28 Dec 2005 15:25:30 -0800,
[EMAIL PROTECTED] wrote:
> hi, i have the following recursive function (simplified to demonstrate
> the problem):
def reTest(bool):
> ... result = []
> ... if not bool:
> ... reTest(True)
Don't do that. Do this instead:
result =
the final returned value is: []
the two values printed is (note i only have one print statement
printing "print result",. however, in the actualality, it's printed
twice):
printing result:
['should be the only thing returned']
printing result:
[]
therefore, sadly, i don't thinkg you've understand
[EMAIL PROTECTED] wrote:
def reTest(bool):
>
> ... result = []
> ... if not bool:
> ... reTest(True)
> ... else:
> ... print "YAHHH"
> ... result = ["should be the only thing returned"]
> ... print "printing result: "
> ... print result
> ... return re
hi, i have the following recursive function (simplified to demonstrate
the problem):
>>> def reTest(bool):
... result = []
... if not bool:
... reTest(True)
... else:
... print "YAHHH"
... result = ["should be the only thing returned"]
... print
12 matches
Mail list logo