[Tutor] Losing the expressiveness of C's for-statement?/RESENDwith example

Ricardo Aráoz ricaraoz at gmail.com
Wed Aug 8 01:05:28 CEST 2007

Stephen McInerney wrote:
> Hi Alan,
> I don't deny the superiority of the underlying language design,
> I'm just pointing out the very real mindjolting effect of Python not
> supporting the universal syntax. Java is closer to C than Python is.
> I'm bringing this up as one hurdle to migration, not a fundamental flaw.
> Don't you agree that the Python tutorial should say something simple
> and accessible to beginners like: "For all for-loop constructs where the
> iteration can't be written as a simple range object, you probably want to
> transform it to a while-loop, (or the more advanced option being a 
> generator)"?
> I think the tutorial is lacking on this (should I email Fred Drake?)
> Instead of leaving C and Java people cold scratching their heads about
> why they think the language is hopelessly quirky and not (syntactically) 
> fully-featured?
> One of our aims should be to write code which is at least understandable to
> programmers of other languages.
>> Sorry I meant to pick a tangible example to focus the discussion:
>> This one cannot be (easily) translated to use Python's range()
>> operator for (i=30000; i>0; i=i/2) { ... }
>> You don't give us any reason why you want to generate a set
>> of numbers from 30,000 down to zero decreasing by half each
>> time: 30,000, 15,000, 7500, 3750, etc
>> To understand the Pythonic solution to the problem we would
>> need to know what those numbers were required for so that we
>> could determine if another python data structure might be more
>> appropriate.
> Yes I did: it occurs in a quicksort as we halve the stepsize each time,
> on an array of size 60000.
> Can you please give me your answer on this? We have to transform it to
> a while-loop? (or write a custom iterator?)

Or just the usual? A recursive function? Elegant, succinct.

More information about the Tutor mailing list