我正在用kivy(python)制作考试应用程序,我在获得正确答案方面遇到了问题。我有从拉丁语单词到斯洛文尼亚语单词的口述翻译示例(键是拉丁语单词,值是斯洛文尼亚语单词):
Dic = {"Aegrotus": "bolnik", "Aether": "eter"}
所以问题是,当2个或3个拉丁单词的意思与1个斯洛文尼亚单词的意思相同时,反之亦然。例如:
Dic = {("A", "ab"): "od", "Acutus": ("Akuten", "Akutna", "Akutno"), "Aromaticus": ("Dišeč", "Odišavljen")}
例如:
在你们看到的应用程序的图片上,我必须翻译“Agito”是什么意思“stresam”,所以我的问题是如何检查它的多个键,它的值是什么
我希望你能理解我的问题:)
首先,你必须能够从图片中显示的应用程序中获取文本输出,然后使用字典进行检查
而字典的设计方式也使得它难以检查。您应该这样设计:键只是一个字符串,值是一个列表。例如:
现在,在您从应用程序中获取文本后,让我们假设它是
text = 'ab:id'
。您将其拆分为键和值,然后签入dict:让我们试试看
您是否只需要从拉丁语翻译->;斯洛文尼亚人而不是相反?如果是这样的话,就让每个键都成为一个单词。多个键具有相同的值是可以的:
每次查找if-then的形式为
Dic[latin] -> slovenian
,其中latin
是单个单词slovenian
是一个或多个单词你可以用
dict.items()
(dict.iteritems()
来表示python2,但我为什么还要提到这个呢?)所以试试类似的方法
相关问题 更多 >
编程相关推荐