例如,我有这个:
alphabetValues = {"a":1,"b":2,"c":3,"d":4,"e":5,"f":6,"g":7...
是否有可能代替:
print(alphabetValues["c"])
拥有能够获得的东西" e"如果我在一个词典中搜索了5个。
" E":5
提前致谢。
答案 0 :(得分:0)
为什么不设置字母表?
alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
print(alphabet[0]) #will print out 'a'
print(alphabet[25]) #will print out 'z'
请注意,所有值均低于预期值。
答案 1 :(得分:0)
根据jonrsharpe的建议,你需要改变你的词典:
alphabetValues = {"a":1,"b":2,"c":3,"d":4,"e":5,"f":6,"g":7}
revalpha={v:k for k,v in alphabetValues.iteritems()}
>>> revalpha[5]
'e'