Welcome, guest | Sign In | My Account | Store | Cart
def containsAny(str, set):
    """Check whether 'str' contains ANY of the chars in 'set'"""
    return 1 in [c in str for c in set]

def containsAll(str, set):
    """Check whether 'str' contains ALL of the chars in 'set'"""
    return 0 not in [c in str for c in set]

if __name__ == "__main__":
    # unit tests, must print "OK!" when run
    assert containsAny('*.py', '*?[]')
    assert not containsAny('file.txt', '*?[]')
    assert containsAll('43221', '123')
    assert not containsAll('134', '123')
    print "OK!"

History

  • revision 2 (22 years ago)
  • previous revisions are not available