new in programing

James Stroud jstroud at mbi.ucla.edu
Fri Dec 9 16:45:55 EST 2005


Cameron Laird wrote:
> In article <mailman.1914.1134158780.18701.python-list at python.org>,
> Mike C. Fletcher <mcfletch at vrplumber.com> wrote:
> 
>>Python iterates over "things" (objects), of which integer numbers are 
>>just one possible choice.  The range built-in command produces ranges of 
>>integers which are useful for tasks such as this.
>>

[...clip (something that begs of recursion)...]

> I don't think the list comprehension helps, in this case--although
> it hints at the temptation of an eval-able expression which is 
> briefer.  More on that, later.

This goes backwards. Going forwards is left as an exercise for whomever:


def do_something(*args):
   print args

def do_deeply(first, depth, lim, todo, inc, *args):
   if depth < lim:
       do_deeply(first+inc, depth+inc, lim, todo, inc, *args)
   if first < depth:
     do_deeply(first+inc, depth, lim, todo, inc, *args + (first,))
   else:
     do_something(*args)

do_deeply(first=1, depth=6, lim=8, todo=do_something, inc=1)


James



More information about the Python-list mailing list