尽管洛奇的答案可能是最简单的方法
要求
您可以使用循环,只需循环遍历字典中的每个项即可手动比较每个项:
team = input('enter team name: ')
for item in x:
if x[item] == team:
print(item)
如果需要显示用户是否进入城市或团队的匹配项,只需检查两项:
team = input('enter team or city name: ')
for item in x:
if x[item] == team:
print(item)
elif item == team:
print(x[item])