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

Alan Gauld alan.gauld at btinternet.com
Sun Jul 22 00:22:45 CEST 2007


"Terry Carroll" <carroll at tjc.com> wrote

> Basically, I have a string s, and I want to print it out only if 
> every
> character in it is printable

Here is my attempt...

def isPrintable(s)
    import string
    return not filter(lambda c: c not in string.printable, s)

But thats very similar to your LC version just slightly more
readable - to me at least!

Alan G.
Just back from a weeks vacation :-)





More information about the Tutor mailing list