python名词同义词只替换2个_用同义词替换句子中的每个单词的Python程序

基本上,我想做的是创建一个程序,将一个句子/段落作为用户输入,查找每个单词的同义词,并用同义词替换该词。到目前为止,我创建的这个程序运行得很好,但是有一些问题/人为错误/逻辑错误。我现在得到的是:response=input("Enter what you want to thesaurize")

orig=response #puts user input into a string

num=orig.count(" ")+1 #finds number of words in the sentence

orig=orig.split(" ") #turns the sentence into a list of its words

new=[] #creates a new list to put the new words in, in case I'd want to go back to the original sentence for any reason

for i in range (num):

if orig[i] not in badWords: #makes sure that the word is not a no-synonym word like "the" or "be"

new.insert(i, myFuncs.replace(orig[i])) #the replace function (which I put in a separate module for neatness purposes) looks up the word on thesaurus.com and replaces it with a synonym

else:

new.insert(i,

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值