Recursive function not returning value
George Yoshida
ml at dynkin.com
Fri Sep 17 03:22:54 EDT 2004
Derek Rhodes wrote:
> OK, I have a recursive function that should return a list, but doesn't
>
> <start session>
>
> def test(word):
> if type(word) == str:
> print "it's a word"
> test([word])
>
> if type(word) == list:
> print "The conditional worked, see ->", word
> return word
>
> What am I missing?
You are forgetting to return the value.
change this part ::
if type(word) == str:
print "it's a word"
test([word])
to
if type(word) == str:
print "it's a word"
return test([word]) # return the result of test([word])
George
More information about the Python-list
mailing list