Alan Gauld wrote:
> "wesley chun" <[EMAIL PROTECTED]> wrote
>
>   
>> the solutions using LCs above are great when it comes to an 
>> expressive
>> piece of code in a one-liner, but i feel there's a waste of
>> time/memory.  the use of GEs is better, but it still has to iterate
>> over the entire string when i don't feel that it should be necessary
>>     
>
> One of my only peeves with LCs is that they always iterate to the end,
> I'd like an optional extra 'until' clause, like:
>
> lst = [n for n in veryBigSequence if someTest(n) until anotherTest(n)]
>
> This would act as usual until the final expression was true at which
> point it would stop iterating.
>   
How about:

lst = [n for n in itertools.takewhile(anotherTest(), veryBigSequence] if 
someTest(n)] # reverse the logic of anotherTest


> If I could find the time/inclination I might even try throwing it in 
> as
> a PEP sometime...
>
> I don't think it would break much old code because (a) its an optional
> extra at the end of the LC and (b) 'until' isn't used in Python so 
> far...
>
> Alan G. 
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>   


-- 
Bob Gailer
510-978-4454 Oakland, CA
919-636-4239 Chapel Hill, NC


_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to