CheckIO House Password

斯蒂芬和索菲亚对于一切都使用简单的密码,忘记了安全性。请你帮助尼古拉开发一个密码安全检查模块。如果密码的长度大于或等于10个符号,至少有一个数字,一个大写字母和一个小写字母,该密码将被视为足够强大。密码只包含ASCII拉丁字母或数字。
输入: 密码 (str, unicode)。
输出: 密码的安全与否,作为布尔值(bool),或者任何可以转换和处理为布尔值的数据类型。你会在结果看到转换后的结果(True False)Example:	
        checkio('A1213pokl') == False
        checkio('bAse730onE') == True
        checkio('asasasasasasasaas') == False
        checkio('QWERTYqwerty') == False
        checkio('123456123456') == False
        checkio('QwErTy911poqqqq') == True


首先想到的就是用正则表达式来解,贴代码:
 
    
import re
def checkio(data):
    r1 = re.search(r'[0-9]+',data)
    r2 = re.search(r'[a-z]+',data)
    r3 = re.search(r'[A-Z]+',data)
    r4 = re.match(r'\w{10,}',data)
    if bool(r1) and bool(r2) and bool(r3) and bool(r4):
        return True
    else:
        return False
    #replace this for solution


#Some hints
#Just check all conditions


if __name__ == '__main__':
    #These "asserts" using only for self-checking and not necessary for auto-testing
    assert checkio('A1213pokl') == False, "1st example"
    assert checkio('bAse730onE4') == True, "2nd example"
    assert checkio('asasasasasasasaas') == False, "3rd example"
    assert checkio('QWERTYqwerty') == False, "4th example"
    assert checkio('123456123456') == False, "5th example"
    assert checkio('QwErTy911poqqqq') == True, "6th example"

 
    
随后看了一下NO.1 的解法,不得不服:	
checkio = lambda s: not(
        len(s) < 10
        or s.isdigit()
        or s.isalpha()
        or s.islower()
        or s.isupper()
    ) 

你可能感兴趣的:(python)