Python recursion with list returns None
Posted
by newman
on Stack Overflow
See other posts from Stack Overflow
or by newman
Published on 2010-04-08T10:41:09Z
Indexed on
2010/04/08
10:43 UTC
Read the original article
Hit count: 232
def foo(a):
a.append(1)
if len(a) > 10:
print a
return a
else:
foo(a)
Why this recursive function returns None (see transcript below)? I can't quite understand what I am doing wrong.
In [263]: x = [] In [264]: y = foo(x) [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] In [265]: print y None
© Stack Overflow or respective owner