use*_*941 3 python dictionary lowercase uppercase
我有这个需要转换为小写的Python字典.字典由需要对不区分大小写输入的数据组成,例如,它适用于resp ='GBR'或'gbr'.希望我在这里有意义.任何帮助将非常感谢!
resp = raw_input('Which country is ' + record['name'] + ' in? ')
print " "
valid = {'GBR': ['GBR',
'United Kingdom',
'UK',
'Great Britain and Northern Island',
'GB'
],
'IRL': ['IRL',
'Eire',
'Republic of Ireland'
]
}
if resp in valid[record['sov']]:
answ = 'Yes, ' + record['name'] + ' is in the ' + resp
Run Code Online (Sandbox Code Playgroud)
如果它需要对应不区分大小写的输入,我建议.lower()您在输入和字典值之间进行比较时添加一个调用,而不是仅为此创建/转换第二个字典.
但是,鉴于你的字典已经是大写的,我会用.upper()你的输入大写来转换你的字典,而不是反过来做