[Tutor] How to determine if every character in one string isinanother string?

Alan Gauld alan.gauld at btinternet.com
Mon Jul 23 23:46:23 CEST 2007

"wesley chun" <wescpy at gmail.com> 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.

If I could find the time/inclination I might even try throwing it in 
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 

Alan G. 

More information about the Tutor mailing list