如何将列表中的元素作为值添加到dictioanry中

时间:2018-03-04 13:24:27

标签: python list dictionary

我想写动词结合符,我发现了最好的方法。 我创建了结尾列表和给定单词的共轭形式列表。 在字典中,人名是键,现在我想将列表元素导入为字典值。

我写了这样的东西:

def conjugar_indicativo_presente(word):

endings_ar = ['o', 'as', 'a', 'amos', 'am']
endings_ir = ['o', 'es', 'e', 'imos', 'em']
endings_er = ['o', 'es', 'e', 'emos', 'em']
persons = ['Eu/I', 'Tu/You', 'Ele/Ela/você/He/She/It', 'Nós/We', "Else/Elas/vocês/They"]

conjugated_forms = []
final = dict()

if not isinstance(word, str):
    return 'Palavra incorreta/Incorrect word'

if word.endswith('ar'):
    for ending in endings_ar:
        conjugated_forms.append(word[:-2] + ending)
        list = zip(persons, conjugated_forms)
        final_conjugated_forms = dict(list)  
    return final_conjugated_forms
elif word.endswith('er'):
    for ending in endings_er:
        conjugated_forms.append(word[:-2] + ending)
        list = zip(persons, conjugated_forms)
        final_conjugated_forms = dict(list)  
    return final_conjugated_forms
elif word.endswith('ir'):
    for ending in endings_ir:
        conjugated_forms.append(word[:-2] + ending)
        list = zip(persons, conjugated_forms)
        final_conjugated_forms = dict(list)  
    return final_conjugated_forms

我尝试了另一种方式,而不是通过for循环将列表转换为字典 但我没有成功 你有什么提示我应该用什么? 还有一些(让我们说)自动化方式?

此致

0 个答案:

没有答案