From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Stephen McInerney

From: [EMAIL PROTECTED]; tutor@python.org
>>As to your particular case one non while option would be a generateor:
>>
>>def half(n):
>>     while int(n) > 0:
>>        n = n/2
>>        yield n
>>
>>for x in half(300): print x,

>It's ok but it's visually clunky. while-loop wins for clarity. lambda
would also be too quirky.
>I know the generator is more runtime-efficient.
>It's regrettable we have to choose between the clear and the efficient,
in this situation.

I would have to disagree completely.  Knowing both C and Python
intimately now, I find this Pythonic expression far easier to read than
the overly-verbose C statement.  The nice thing about python is that it
makes chunking much easier than C which increases readability.  Remember
that these lines would be visually separated.  In the algorithmic part
of the quicksort all you would have is

fox x in decrement_by_halves(300):
        do stuff

Note that I changed the name of the generator to be more explicit.  The
loop now tells exactly what is being generated.  No more tearing apart
an ugly C for construct which forces implementation of the generator at
a place where you don't really need to know about it.

Jeff
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to