On May 4, 1:34 am, Cameron Simpson <c...@zip.com.au> wrote:
> On 03May2010 22:02, rickhg12hs <rickhg1...@gmail.com> wrote:
> | 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]])
>
> You need:
>     return recur_trace(x[1:], y + [x[0]])
>
> Otherwise the function returns None.

Ah, an explicit "return" is required.  Thanks!
[To bad there's no tail recursion optimization.]  8-(

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to