more fun with PEP 276

phil hunt philh at comuno.freeserve.co.uk
Wed Dec 12 11:32:46 EST 2001


On Mon, 10 Dec 2001 16:04:04 -0800, James_Althoff at i2.com <James_Althoff at i2.com> wrote:
>
>wtanksley wrote:
>>>  >>> for i in -5 // span // 5:  # closed-closed
>>>  ...     print i,
>>>  -5 -4 -3 -2 -1 0 1 2 3 4 5
>>
>>Intriguing.  Odd.  Perverted.  Words would fail me, but doggone
>>it, I find myself liking it.
>
>Thanks, Billy.  I was starting to wonder if
>*anyone* was going come around to appreciating
>its quirky wholesome-ness. <wink>
>
>>The scary thing is that despite the ENORMOUS gap between the purpose
>>of the / operator and your abuse of it (help! I'm being repressed!), I
>>can still read this naturally: "span over length of myList".
>>
>>Minor niggle: how would users remember which operator represents which
>>type of range ending?  Do you have a proposed mnemonic?

how about:

   for i in -5 to 5:

or

   for i in -5 to 5 step 2:


Here, "to" and "to...step" are keywords that create an xrange with the
required values; when used deirecvtly in a for loop, the compiler could
presumably optimise that out, but this should still work:

  values = -5 to 5 step 3
  for i in values:
     print i

should result in:
-5
-2
1
4



-- 
*** Philip Hunt *** philh at comuno.freeserve.co.uk ***




More information about the Python-list mailing list