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()
    ) 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值