Recursive functions not returning lists as expected

Charles C.Sanders at DeleteThis.Bom.GOV.AU
Tue May 4 01:32:18 EDT 2010


"rickhg12hs" <rickhg12hs at gmail.com> wrote in message 
news:2ff16113-4f79-4dcf-8310-35d2b91e89dc at o11g2000yqj.googlegroups.com...
> Would a kind soul explain something basic to a python noob?
>
> Why doesn't this function always return a list?
>
> def recur_trace(x,y):
>  print x,y
>  if not x:
>    return y
>  recur_trace(x[1:], y + [x[0]])
>

shouldn't it be
   return recur_trace(x[1:], y + [x[0]])
otherwise the recursive call returns nothing

Charles 





More information about the Python-list mailing list