Robert Kern wrote:
actuary77 wrote:
#
# non-generator
#
def f1(afunc,aseed,n):
values = [afunc(aseed)]
for i in range(n-1):
values.append(afunc(values[-1]))
return values[-1]
_b
Robert Kern wrote:
actuary77 wrote:
Recurse from time: 4.305942779541 seconds
Iter from time: 0.009904632568359 seconds
No comparison, why is recursion so slow?
I usually don't delve too deeply into language design issues, so I hope
others will correct me if I
Heiko Wundram wrote:
On Wednesday 02 March 2005 06:03, actuary77 wrote:
It now makes sense if I write it, (simple):
def rec2(n):
if n == 0:
return []
else:
return [n] + rec2(n-1)
Or, if you're not interested in a recursive function to do this job (which
should b
Heiko Wundram wrote:
On Wednesday 02 March 2005 06:03, actuary77 wrote:
It now makes sense if I write it, (simple):
def rec2(n):
if n == 0:
return []
else:
return [n] + rec2(n-1)
Or, if you're not interested in a recursive function to do this job (which
should b
actuary77 wrote:
I am trying to write simple recursive function to build a list:
def rec(n,alist=[]):
_nl=alist[:]
print n,_nl
if n == 0:
print n,_nl
return _nl
else:
_nl=_nl+[n]
rec(n-1,_nl)
_nl=[]
_nl=rec(4)
print _nl
### shouldn't this work
I am trying to write simple recursive function to build a list:
def rec(n,alist=[]):
_nl=alist[:]
print n,_nl
if n == 0:
print n,_nl
return _nl
else:
_nl=_nl+[n]
rec(n-1,_nl)
_nl=[]
_nl=rec(4)
print _nl
### shouldn't this work?
_nl=rec(4)
The output