我创建了一个函数,它将在a中查找年龄Dictionary
并显示匹配的名称:
dictionary = {'george' : 16, 'amber' : 19}
search_age = raw_input("Provide age")
for age in dictionary.values():
if age == search_age:
name = dictionary[age]
print name
Run Code Online (Sandbox Code Playgroud)
我知道如何比较和找到我只是不知道如何显示这个人的名字的年龄.另外,KeyError
由于第5行,我得到了一个.我知道这不正确,但我无法弄清楚如何让它向后搜索.
我有一个脚本读取输入,然后列出它,但我希望它将大写字母转换为小写字母,我该怎么做?
这就是我得到的
for words in text.readlines():
sentence = [w.strip(',.') for w in line.split() if w.strip(',.')]
list.append(sentence)
Run Code Online (Sandbox Code Playgroud)