gpt4 book ai didi

python-2.7 - 为什么是TypeError : unhashable type: 'list' coming up?

转载 作者:行者123 更新时间:2023-12-02 11:01:44 30 4
gpt4 key购买 nike

Hello guys just encountered an error after running my final code and i was wondering what i have done wrong?



汇入

def password():
打印(“输入密码\ n \ n密码必须超过6个字符。\ n')
while True:
password = raw_input('Password: ')
if 6 < len(password):
break
print ('The password must be more than 6 characters.\n')

password_scores = {0:'Very weak', 1:'Weak', 2:'Medium', 3:'Strong', 4:'Very strong'}
password_strength = dict.fromkeys(['has_upper', 'has_lower', 'has_num' , 'has_sym', False])
if re.search(r'[A-Z]', password):
password_strength['has_upper'] = True
if re.search(r'[a-z]', password):
password_strength['has_lower'] = True
if re.search(r'[0-9]', password):
password_strength['has_num'] = True
if re.search(list("[ !#$%&'()*+,-./[\\\]^_`{|}~ ]") , password):
password_strength['has_sym'] = True

score = len([b for b in password_strength.values() if b])

print ('Password is %s' % password_scores[score])

密码()

最佳答案

将您的if语句替换为以下语句,它将起作用:

if re.search("[!#$%&'()*+,-./[\\\]^_`{|}~ ]" , password):
password_strength['has_sym'] = True

关于python-2.7 - 为什么是TypeError : unhashable type: 'list' coming up?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36133527/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com