【问题标题】:Why is the TypeError: unhashable type: 'list' coming up?为什么会出现 TypeError: unhashable type: 'list'?
【发布时间】:2016-03-21 14:20:51
【问题描述】:

大家好,我在运行我的最终代码后遇到了一个错误,我想知道我做错了什么?

重新导入

定义密码(): print ('输入密码\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])

密码()

【问题讨论】:

    标签: python-2.7 compiler-errors


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2021-03-14
      • 2020-04-07
      • 1970-01-01
      • 2015-02-11
      • 2019-10-11
      • 2020-03-27
      • 2020-05-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多