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

Heiko Wundram modelnine at ceosg.de
Wed Mar 2 06:37:58 CET 2005


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 be way faster...):

>>> def iter1(n):
...     nl = range(1,n+1)
...     nl.reverse()
...     return nl
...
>>> print iter1(4)
[4, 3, 2, 1]

-- 
--- Heiko.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20050302/d8744a96/attachment.pgp>


More information about the Python-list mailing list