PEP 234: Iterators

Fredrik Lundh fredrik at pythonware.com
Mon May 7 13:02:52 EDT 2001


Neil Schemenauer wrote:
> > OK. Probably
> >
> > 1, 3 ... 11
> >
> > is right way to specify the equivalent of
> >
> > range(1, 11+1, 3-1)
>
> That doesn't seem very obvious to me.

if the [first, second, ..., last] notation isn't obvious to you,
you've been programming too long ;-)

> It might be useful to look what Haskell does in this case.  I
> think they use [0..9] to mean the same thing as range(10).
> I don't know what they do for non-contiguous ranges.

or you could look at SETL's arithmetic formers:

    { <v1> [, <v2>] .. <v3> }

    The set created will contain the integers <v1>,
    <v2>, <v1> + (<v2> - <v1>) ... <v3>.  The
    middle element is optional and defaults to
    <v1> + 1.

(Python already provides SETL's enumerated formers [list displays]
and general formers [list comprehensions].   arithmetic formers are
all there's left to steal ;-)

Cheers /F





More information about the Python-list mailing list