PEP 284, Integer for-loops

Greg Ewing greg at cosc.canterbury.ac.nz
Wed Mar 6 22:00:26 EST 2002


Steve Lamb wrote:
> 
> On Wed, 06 Mar 2002 16:57:03 -0800, David Eppstein <eppstein at ics.uci.edu>
> wrote:
> > Did you try running range(n-1,0)?  What list did it give you?
> 
> >>> range(-10,0)
> >>> [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1]
> 
>     And?  How does this prove your point

The point was, I think, that

  >>> n = 10
  >>> range(n-1,-1,-1)
  [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]

but

  >>> foo = range(n-1,0)
  >>> foo.reverse()
  >>> foo
  []

> In your notation how would you do the following?
> 
> for x in range(n-1,-1,-2):

for 0 <= i < n/2:
  x = 2*i + 1
  ...

-- 
Greg Ewing, Computer Science Dept, University of Canterbury,	  
Christchurch, New Zealand
To get my email address, please visit my web page:	  
http://www.cosc.canterbury.ac.nz/~greg



More information about the Python-list mailing list