syntax enhancement

Westley Martínez anikom15 at gmail.com
Wed Oct 5 17:28:22 EDT 2011


On Wed, Oct 05, 2011 at 01:31:41PM -0500, Tim Chase wrote:
> On 10/04/11 20:45, Terry Reedy wrote:
> >On 10/4/2011 9:50 AM, Valiev Sergey wrote:
> >
> >>- `[]` - used for list comprehension,
> >>- `()` - used for generators,
> >>- `[start:stop]` / `[start:stop:step]` - used for slices.
> >>The idea is to use `(start:stop)` / `(start:stop:step)` as 'lazy
> >>evaluated' slices (like itertools.islice).
> >>What do you think about it?
> >
> >a(b) is already used for function calls. Making a(b:c) be something
> >unreleated does not seem like a good idea to me. At present, a[b:c] ==
> >a[slice(b,c)]. However, a(slice(b,c)) is already a function call and
> >could not equal a(b:c).
> 
> I'm very -1 on the initial proposal with parens, but I wouldn't
> object to generators growing a method (__getitem__?) to do slices
> via itertools, something like
> 
>   gen = (a for a in iterator if test(a))
>   for thing in gen[4::2]:
>     do_something(thing)
> 
> acting something like
> 
>   gen = (a for a in iterator if test(a))
>   for thing in itertools.islice(gen, start=4, step=2):
>     do_something(thing)
> 
> -tkc
> 
> 
> 
>

Wait, how would this work fundamentally?  A list can be sliced because
all the values are there.  A generator does not have all its value at
once (it generates each value as requested).  I don't like change so I
look at these kinds of suggestions with lots of scrutiny and biased
criticism.



More information about the Python-list mailing list