syntax enhancement
Tim Chase
python.list at tim.thechases.com
Wed Oct 5 14:31:41 EDT 2011
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
More information about the Python-list
mailing list