def judgePasswordStrength(password): strengthLength = max(0, len(password) - 5) from string import ascii_lowercase, ascii_uppercase, digits, punctuation flags = [bool(set(password) & set(s)) for s in [ascii_lowercase, ascii_uppercase, digits, punctuation]] return min(flags.count(True), strengthLength)