About generators

John Roth newsgroups at jhrothjr.com
Mon Apr 26 10:09:09 EDT 2004


"Peter Hansen" <peter at engcorp.com> wrote in message
news:L-6dnRq_ZvsmjBDdRVn_iw at powergate.ca...
> Andrea Griffini wrote:
>
> > I'm new to python and I really like what I've seen so far
> > with just one exception; the absence of a nice syntax
> > for ranges of integers. I've read PEPs about allowing
> >
> >    for i in 10:
> >      print i
> >
> > and I must say I don't like it very much, but I didn't
> > find a discussion about what looks more natural
> >
> >    for i in 0...9:
> >      print i
> >
> > or
> >
> >    squares = [x*x for x in 1...100]
> >
> > that is having "expr1 ... expr2" returning an iterator
> > from expr1 to expr2 (second limit included).
> >
> > Has this been considered ? If yes (as I suppose) where
> > can I find and explanation about it ?
>
> Google Groups is always helpful for such questions:
>
>
http://groups.google.com/groups?q=integer+range+syntax&meta=group%3Dcomp.lang.python.*
>
> This leads to various threads, such as the "Re: Thoughts on PEP284"
> which had the same proposal as yours and what is, I believe, an
> adequate reason for rejecting it.

As far as I can tell, the appropriate PEP to reference
is 204: range literals. That one proposed using slice
notation, and it was firmly rejected.

I frankly like the idea since .. or ... is an operator, so it
naturally leads to a magic method or two, opening the
door to other types of ranges, such as reals or dates,
etc...

John Roth
>
> -Peter





More information about the Python-list mailing list