Python 2.7错误:';设置';对象没有属性'__获取项目';在具有原始输入条件之后

Python 2.7错误:';设置';对象没有属性'__获取项目';在具有原始输入条件之后,python,algorithm,python-2.7,error-handling,Python,Algorithm,Python 2.7,Error Handling,用户输入后出错,总是告诉我set对象没有属性。我已经研究了其他问题,但在我的场景中没有取得任何成功。我试过很多东西。基本上,这个程序有一个我创建的密码,我想把用户的字符替换成我的密码字母表。顺便说一下,出于保密目的,我已经替换了这些译文。希望有人能帮我解决这个问题 cache_list = { 'result' } usr = raw_input("Usr: ") if 'a' in usr: result1 = usr.replace('a', "hash1" , 100000000

用户输入后出错,总是告诉我set对象没有属性。我已经研究了其他问题,但在我的场景中没有取得任何成功。我试过很多东西。基本上,这个程序有一个我创建的密码,我想把用户的字符替换成我的密码字母表。顺便说一下,出于保密目的,我已经替换了这些译文。希望有人能帮我解决这个问题

cache_list  = {
'result'
}

usr = raw_input("Usr: ")



if 'a' in usr:
result1 = usr.replace('a', "hash1" , 1000000000)
cache_list['result'].append(result1)


if 'b' in usr:
    result2 = usr.replace('b', "hash2" , 1000000000)
    cache_list['result'].append(result2)

if 'c' in usr:
cache_list['result3'] = usr.replace('c', "hash3" , 1000000000)
cache_list['result'].append(result3)


if 'd' in usr:
result4 = usr.replace('d', "hash4" , 1000000000)
cache_list['result'].append('result4'
                                )


if 'e' in usr:
result5 = usr.replace('e', "hash5" , 1000000000)
cache_list['result'].append(result5)


if 'f' in usr:
result6 = usr.replace('f', "hash6" , 1000000000)
cache_list['result'].append(result6)

if 'g' in usr:
result7 = usr.replace('g', "hash7" , 1000000000)
cache_list['result'].append(result7)


if 'h' in usr:
result8 = usr.replace('h', "hash8" , 1000000000)
cache_list['result'].append(result8)


if 'i' in usr:
result9 = usr.replace('i', "hash10" , 1000000000)
cache_list['result'].append(result9)


if 'j' in usr:
result10 = usr.replace('j', "hash11" , 1000000000)
cache_list['result'].append(result10)


if 'k' in usr:
result11 = usr.replace('k', "hash12" , 1000000000)
cache_list['result'].append(result11)


if 'l' in usr:
result12 = usr.replace('l', "hash13" , 1000000000)
cache_list['result'].append(result12)


if 'm' in usr:
result13 = usr.replace('m', "hash14" , 1000000000)
cache_list['result'].append(result13)


if 'n' in usr:
result14 = usr.replace('n', "hash15" , 1000000000)
cache_list['result'].append(result14)


if 'o' in usr:
result15 = usr.replace('o', "hash17" , 1000000000)
cache_list['result'].append(result15)


if 'p' in usr:
result16 = usr.replace('p', "hash18" , 1000000000)
cache_list['result'].append(result16)



if 'q' in usr:
result17 = usr.replace('q', "hash19" , 1000000000)
cache_list['result'].append(result17)


if 'r' in usr:
result18 = usr.replace('r', "hash20" , 1000000000)
cache_list['result'].append(result18)



if 's' in usr:
result19 = usr.replace('s', "hash21" , 1000000000)
cache_list['result'].append(result19)




if 't' in usr:
result20 = usr.replace('t', "hash22" , 1000000000)
cache_list['result'].append(result20)




if 'u' in usr:
result21 = usr.replace('u',"hash23" , 1000000000)
cache_list['result'].append(result21)



if 'v' in usr:
result22 = usr.replace('v',"hash24" , 1000000000)
cache_list['result'].append(result22)



if 'w' in usr:
result23 = usr.replace('w',"hash26" , 1000000000)
cache_list['result'].append(result23)




if 'x' in usr:
result24 = usr.replace('x',"hash27" , 1000000000)
cache_list['result'].append(result24)





if 'y' in usr:
result25 = usr.replace('y',"hash28" , 1000000000)
cache_list['result'].append(result25)





if 'z' in usr:
    result26 = usr.replace('z',"hash29" , 1000000000)
cache_list['result'].append(result26)





if ' ' in usr:
result27 = usr.replace(' ', "space" , 1000000000)
cache_list['result'].append(result27)



print cache_list[result]
在初始化
缓存列表
变量时,您(可能是意外地)创建了一个集合而不是字典。尝试使用:

cache_list = {"result": ""}
这将在字典中创建一个键
result
,并将其值设置为
“”
(空字符串)

下面是一个控制台示例:

>>> cache_list = {"result"}
>>> type(cache_list)
<type 'set'>

摘要:
{“result”}
创建一个集合,但是
{“result”:“}
创建一个dict既然您想存储在列表中,缓存列表应该是这样的:

cache_list = {"result": []}

usr = raw_input("Usr: ")

if 'a' in usr:
    result1 = usr.replace('a', "hash1", 1000000000)
    print result1
    cache_list['result'].append(result1)

if 'b' in usr:
    result2 = usr.replace('b', "hash2", 1000000000)
    cache_list['result'].append(result2)

print cache_list["result"]

你有什么问题?你看到了什么行为?你期望看到什么?
cache_list = {"result": []}

usr = raw_input("Usr: ")

if 'a' in usr:
    result1 = usr.replace('a', "hash1", 1000000000)
    print result1
    cache_list['result'].append(result1)

if 'b' in usr:
    result2 = usr.replace('b', "hash2", 1000000000)
    cache_list['result'].append(result2)

print cache_list["result"]