[Tutor] Forgot something...

Kent Johnson kent37 at tds.net
Fri Jan 25 12:49:31 CET 2008


Timothy Sikes wrote:
> Sorry, but in my previous message, I realized that I hadn't changed the 
> code from doesNotHave...  It's supposed to be x.find(), not 
> x.startswith......

You meant to write:

def doesNotHave(exclude, root):
     for x in exclude:
         if root.find(x) > -1:
             return False
     return True

This can be written as
def doesNotHave(exclude, root):
     for x in exclude:
         if x in root:
             return False
     return True

or

def doesNotHave(exclude, root):
     return not any(x in root for x in exclude)

Kent


More information about the Tutor mailing list