[Tutor] How to determine if every character in one string is inanother string?
malaclypse2 at gmail.com
Mon Jul 23 02:48:19 CEST 2007
On 7/21/07, Alan Gauld <alan.gauld at btinternet.com> wrote:
> > all(char in string.printable for char in testString)
> What is all?
> Is that a 2.5 thing (I'm still on 2.4 here)
Yes, it's a 2.5 thing. All returns true if all of the elements of an
iterable are true. According to the docs, it is the equivalent of the
for element in iterable:
if not element:
Using 'all' with a generator expression has the virtue of only needing
to look at the string until it finds a single element that is false,
and then returning. Not only that, it's concise (a single line) and
quite readable (at least to me).
More information about the Tutor