PEP 276 Simple Iterator for ints

Bjorn Pettersen BPettersen at NAREX.com
Thu Nov 15 22:47:32 CET 2001


> From: Ken Seehof [mailto:kseehof at neuralintegrator.com] 
> 
> > Ken Seehof wrote:
> > >Hey, what ever happened to the int[:10] iterator idea?
> > >
> > >>>> for i in int[2:10:2]: print i,
> > >2 4 6 8
> >
> > Nothing actually *happened* to it. ;-)
> >
> > It needs a PEP (or needs to be added to an existing PEP).

[...]

> 1. Integer slicing is better than iter(n), and accomplishes 
> the same objectives. 2. Integer slicing is just a different 
> spelling for xrange.  So don't bother. 3. Therefore, might as 
> well just reject 276. 4. But wait, xrange and range are 
> really ugly in for loops. 5. So let's do integer slicing after all.

Jim has been good enough to write up a PEP for his proposal, so if you
have a counter proposal I suggest you do the same.

Personally, I don't like the slice idea because the common usage would
be:

  for i in int[:len(sequence)]: ...

Which is hardly more readable than:

  for i in range(len(sequence)): ...

Vs. the proposed:

  for i in len(sequence): ...

+1 for PEP 276 from me.

-- bjorn




More information about the Python-list mailing list