more fun with PEP 276

James_Althoff at i2.com James_Althoff at i2.com
Wed Dec 5 15:08:41 EST 2001


David Eppstein wrote:
>But there isn't a huge distinction between "works only in a for loop" and
>"produces general-purpose iterators" because of list comprehensions:
>    L = [i for -5 <= i <= 5]

Agreed.  Still

    tuple([i for -5 <= i <= 5])  # actualize list first, then convert.
extra syntax, too

isn't quite as nice as

    tuple(-5 <= ... <= 5)

Or if I need to pass an interval around I would like to be able to say:

    myObject.setInterval(left < ... <= right)  # I really want an interval
not an actualized list

instead of having to resort back to:

    myObject.setInterval(xrange(left+1,right+1)  # left < i <= right
doesn't help me here

Plus, "-5 <= i <= 5" doesn't provide a step value (other than 1 and -1 --
important to some, not important to others).

And, to me, the following is reasonably clear pseudo-code:

for i in n > ... >= 0:
    for j in i < ... <= n:
        if i == j-1:
            V[i,j] = id
        else:
            V[i,j] = min([q(i,k,j) @ V[i,j] @ V[j,k] for k in i < ... < j])


So I think it would be nearly ideal if one could implement

    -5 <= ... <= 5

instead of

    -5 // span // 5

but with the same functionality.

Jim





More information about the Python-list mailing list