Re: Help- Recursion v. Iter Speed comparison

2005-03-03 Thread actuary77
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

Re: Help- Recursion v. Iter Speed comparison

2005-03-02 Thread actuary77
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&#x

Re: Question - What is a faster alternative to recursion?

2005-03-01 Thread actuary77
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

Re: Help- Recursion v. Iter Speed comparison

2005-03-01 Thread actuary77
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

Re: Help- Simple recursive function to build a list - Sorry for all the noise!

2005-03-01 Thread actuary77
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

Help- Simple recursive function to build a list

2005-03-01 Thread actuary77
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