Python
1import re 2def isValidPassword(password): 3 word_count = len(password) 4 lowercase = password.lower() 5 remove_num = password.replace('1', '').replace('2', '').replace('3', '').replace('4', '').replace('5', '').replace('6', '').replace('7','').replace('8', '').replace('9','').replace('0','') 6 if ' ' not in password and word_count >= 6 and lowercase != password and remove_num != password: 7 return True 8 else: 9 return False 10 11print(isValidPassword('1234567')) 12print(isValidPassword('Abc4eFg')) 13print(isValidPassword("Abc4 eFg")) 14 15re.sub('[0-9]+', '', password) ← この記述法は試しました。
上記コードよりコード量が少ない記述法をご教授ください。
できれば正規表現以外でお願いします。
また、Pythonの文字列置換はreplace()でコツコツやるしかないのでしょうか?
条件は下記の通りです。
・文字列が6以上
・大文字と小文字を含む・
・数字を含む
・スペースがない
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/05/06 08:16
2020/05/06 08:25