python for loop

Rhodri James rhodri at wildebst.demon.co.uk
Tue Mar 31 22:59:36 EDT 2009


On Wed, 01 Apr 2009 03:37:41 +0100, Lada Kugis <lada.kugis at gmail.com>  
wrote:

> On Tue, 31 Mar 2009 19:29:56 -0700, Chris Rebert <clp2 at rebertia.com>
> wrote:
>
>
>> Sort of, but it's *really* not idiomatic. You'd have to declare the
>> arrays to be one longer than they actually are so that array[N] is a
>> valid index. And then you'd end up not using the true first element of
>> the array. Not to mention most library functions use 0-numbering, so
>> you'd have to work around that as well.
>>
>> So, it can be done, but you're going against the grain of the language.
>
> I use fortran libraries, so that is not a problem for me. I only make
> the change once, while transferring the elements ... uhmm, make that
> twice.

Two opportunities to forget to lie about how big your array is :-)

> I wrote in my other post, 0 is weird to me, I have model of solution
> on paper ... if I keep 0 then all comes out different. And while
> comparing, I always get them mixed up. That's why I always try to
> adapt it to the paper situation.

Ever considered adapting the paper situation to it?  You might find
that the results come out more naturally.  Alternatively, idiomatic
Python seems to have a strong tendency not to need subscripting,
since you spend most of your time iterating through lists instead.

-- 
Rhodri James *-* Wildebeeste Herder to the Masses



More information about the Python-list mailing list