所以,我有一个功能,应该要求用户输入一个大陆的名称,然后函数应该通过Dictionary [“values”]来查找该大陆,然后搜索通过字典中的所有国家[“关键字”]打印列表中所有大陆国家。打印与字典值相关的关键字
词典[“值”] =大洲列表 词典[“关键字”] =国家
的名单到目前为止,我有:
def filterCountriesByContinent(self):
continentinp = input(str("Please enter a continent: ")) #user input
if continentinp in self.Dictionary["values"]: #check if input in Dictionary.values
return print(self.Dictionary["keywords"]) #if in Dictionary.values, print off associated countries
else:
return print("That country is not in the Dictionary")
现在它只是打印关闭Dictionary [“关键字”]中的所有国家/地区列表,包括不在输入大陆的国家/地区列表。
难道你没有大陆映射到国家吗? –
'print(self.Dictionary [“keywords”])'总是会打印同样的东西。它不应该与“continentinp”有关吗? –
在前面的函数中,我们接受一个txt文件的输入,将数据拆分为多个部分,并将这些部分与Dictionary [“values”]和Dictionary [“keywords”]关联起来。我试图弄清楚如何将它们联系起来,以便创建可正常工作的不同打印部分。 – MezyMinzy