Translate this to python?

Bengt Richter bokr at oz.net
Wed Jan 4 05:55:07 EST 2006


On 3 Jan 2006 17:42:44 -0800, "KraftDiner" <bobrien18 at yahoo.com> wrote:

>I'm porting a routing from C++ to python.
>There is a complex for loop that I don't know how to code in python
>
>for (i = nPoints-1, j = 0; j < nPoints; i = j, j++)
>
Perhaps most directly comparable semantics (untested):

i = nPoints-1
j = 0
while j<nPoints:
    # whatever body code
    i = j
    j += 1

Not sure what i is really for, but j seems to be independent,
so perhaps (also untested, and caveat: it's past bedtime)

i = nPoints - 1
for j in xrange(nPoints):
    # whatever
    i = j

Regards,
Bengt Richter



More information about the Python-list mailing list