我有一个默认的dict,它有3层嵌入,稍后将用于一个trigram。你知道吗
counts = defaultdict(lambda:defaultdict(lambda:defaultdict(lambda:0)))
然后,我有一个for循环,它遍历一个文档并创建每个字母的计数(以及bicounts和tricounts)
counts[letter1][letter2][letter3] = counts[letter1][letter2][letter3] + 1
我想添加另一层,以便可以指定字母是辅音还是元音。你知道吗
我想能够在辅音和元音上运行我的二元图和三元图,而不是在字母表的每个字母上运行,但我不知道如何做到这一点。你知道吗
假设你需要保持元音和辅音序列的计数,你可以简单地保持一个不同的映射。你知道吗
如果你有一个函数
is_vowel(letter)
,如果True
是元音,如果letter
是辅音,你可以这样做。你知道吗我不确定您到底想做什么,但我认为嵌套dict方法并不像使用平面dict那样干净,在平面dict中,您可以通过组合字符串(即
d['ab']
而不是d['a']['b']
)进行键控。我还输入了代码来检查二元/三元结构是由元音/辅音组成还是由一个混合词组成。你知道吗代码:
输出:
相关问题 更多 >
编程相关推荐