gpt4 book ai didi

python - 找出单词中的音节数

转载 作者:太空狗 更新时间:2023-10-29 20:11:43 25 4
gpt4 key购买 nike

我需要使用 NLTK 找出英语单词中的音节数。这是我到目前为止的代码:

import curses 
from curses.ascii import isdigit
import nltk
from nltk.corpus import cmudict
d = cmudict.dict()
def nsyl(word):
return [len(list(y for y in x if isdigit(y[-1]))) for x in d[word.lower()]]

>>> nsyl(arithmetic)

函数调用后,我收到一个名称错误,指出算术未定义。谁能帮我找出代码中的错误?

最佳答案

你需要在“算术”这个词周围加上引号

关于python - 找出单词中的音节数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5087493/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com