包含多个动词的嵌套字典,其中又包含多个动词。我想回忆一个动词,但我有一个错误
使用此代码,我想打印 Jessica è chiamata alla prova del tris
,然后首先从字典中回忆起单词“chiamare”,然后通过 for 循环检查是否使用单词“è chiamata” (因为杰西卡是一个女性名字,因此有“a”“è chiamatA”)。
for 循环的使用很重要,所以如果您想帮助我,请尝试坚持下去并通过尽可能少地修改它来保持在该循环上,因为循环首先检查哪个是主题,然后与主题相关主题通过在词典中查找来检查要使用哪个单词。我只是用 {verb}
来调用它。
以前我只需要用 {verb}
来调用它,因为在字典中我有两个单独的单词,例如“è chiamata”和“è chiamato”。效果很好。然而现在,我将这两个动词组合成一个动词,即“呼叫”。
问题 所以现在如果我尝试打印,它只会打印 alla prova del tris
(没有她,她被称为或被称为)。
所以我想需要某种方式来明确我想回忆起“chiamare”这个词,然后检查使用“è chiamata”或“è chiamato”哪个。所以我尝试使用 {verb ['chiamare']}
,但我知道它显然不起作用。直到后来我才读到为什么我不能使用这个,所以让我们避免纠结为什么我不必这样写。让我们考虑解决
我在寻找什么? 所以我想要的是:在句子中回忆“call”,让他选择是否使用“is Called”或“Is Called”。 “要选择你需要我的 for 循环,因为你必须首先将它与主语联系起来。我会按顺序写给你我想做的事情:for 循环将主语和动词联系起来。她看到杰西卡的字典说它是阴性的,并且单数,因此 for 循环使用动词“è chiamatA”,因为该动词在字典中是阴性且单数的,但现在我添加了包含这两个动词的动词“chiamare”。 “è chiamato”或“è chiamata”,该项目不再有效,所以我认为有必要表明我想使用 {verb ['to call']} 调用动词“to call”,但是当然。 那么我该
如何解决它呢?
重要:在检查“chiamare”内部是否使用“è chiamato”或“è chiamata”之前,请记住我首先使用循环检查主题,因为谢谢到我放置的循环所以我使用的循环很重要,
你能帮我吗?
Name = {
"Jessica": {"gender" : "female", "quantity" : "singular"},
"David" : {"gender" : "male", "quantity" : "singular"}
}
dictionary_verbs = { "chiamare": {"è chiamata" : { "gender" : "female", "quantity" : "singular"},
"è chiamato" : { "gender" : "male", "quantity" : "singular"}},
#"other_verb": ...
#"other_verb": ...
}
subject = "Jessica"
#Search verb in relation to the subject
verb = ""
for key, value in dictionary_verbs.items():
if Name[subject] == value:
verb = key
break
phrase = (f"{verb['chiamare']} alla prova del tris")
print(phrase)
With this code I would like to print Jessica è chiamata alla prova del tris
, then recall from the dictionary first the word "chiamare", then check whether to use the word "è chiamata" through the for loop (because Jessica is a feminine name and therefore there is the "a" "è chiamatA").
The use of that for loop is important, so if you want to help me, try to stick to it and stay on that loop by modifying it as little as possible, because the loop first checks which is the subject and then in relation to the subject checks which word to use by looking for it in the dictionaries. I just call it with {verb}
.
Previously I only needed to call it with {verb}
, because in the dictionary I had two separate words like "è chiamata" and "è chiamato". It worked fine. Now, however, I have grouped these two verbs into a single verb which is "to call".
PROBLEM
So now if I try to print, it just prints alla prova del tris
(without her she is called or called).
So I thought it takes some way to make it clear that I would like to recall the word "chiamare" and then check which one to use "è chiamata" or "è chiamato". So I tried to use {verb ['chiamare']}
, but it obviously doesn't work, I know. Only later did I read why I can't use this, so let's avoid dwelling on why I don't have to write like this. Let's think about solving
WHAT I AM LOOKING FOR?
So what I would like is: in the sentence recall "call" to let him choose whether to use "is called" or is called. "To choose you need my for loop because you must first relate it to the subject. I'll write you what I want to do in order: the for loop relates the subject and the verb. She sees that Jessica's dictionary says it's feminine and singular, so the for loop uses the verb "è chiamatA" because this verb in the dictionary is feminine and singular. The for loop works correctly. But now that I have added the verb "chiamare" which encloses the 2 verbs "è chiamato" or "è chiamata", the project no longer works. So I thought there was a need to indicate that I wanted to invoke the verb "to call" using {verb ['to call']}, but of course it doesn't work.
So how could I fix it?
IMPORTANT: before checking inside "chiamare" whether to use "è chiamato" or "è chiamata", remember that I first check the subject with the cycle, because thanks to the cycle I put in relation subject and verb. So my cycle I use is important
Can you help me? Thank you
Name = {
"Jessica": {"gender" : "female", "quantity" : "singular"},
"David" : {"gender" : "male", "quantity" : "singular"}
}
dictionary_verbs = { "chiamare": {"è chiamata" : { "gender" : "female", "quantity" : "singular"},
"è chiamato" : { "gender" : "male", "quantity" : "singular"}},
#"other_verb": ...
#"other_verb": ...
}
subject = "Jessica"
#Search verb in relation to the subject
verb = ""
for key, value in dictionary_verbs.items():
if Name[subject] == value:
verb = key
break
phrase = (f"{verb['chiamare']} alla prova del tris")
print(phrase)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下代码应该适用于您的用例。
对评论中的讨论添加以下解释:
以下是您的代码:
如果可能的话,我建议为“dictionary_verbs”字典使用不同的结构/格式。字典的嵌套越多,就会添加更多的 for 循环,如果它是一个大字典,它只会增加太多的时间复杂度。
同样在代码中,我们引入了一个新的“动词”字典,以便我们可以使用它在代码中稍后打印“短语”。如果dictionary_verbs是一个大字典,动词字典也会很大并占用更多空间。
The following code should work for your usecase.
Adding the following explanation for the discussion in comments:
Following is your code:
I would suggest using a different structure/format for the "dictionary_verbs" dictionary if possible. More nested the dictionary is more for-loops will be added and if its a large dictionary it will simply add too much time complexity.
Also in the code, we introduce a new "verb" dictionary so that we can use it to print the "phrase" later in the code. If dictionary_verbs is a large dictionary verbs dictionary also will be large and take up more space.