我正在使用字典文件。我只是需要用词来结束“它”。我在使用计数器计算双辅音时,以这些单词的“ed”结尾。我应该接收回来的代码是(最后3行):查找以字母“it”结尾的单词...否定所有其他单词?
wait waited
worrit worrited
simple= 83 double= 45"
从我有什么,我需要做的就是摆脱没有在结束所有换句话说,“它”和我无法提出解决方案。单词endswith只是重印了一些单词。
words=[line.rstrip() for line in open('')]
wordset=set(words)
count=0
countt=0
for word in words:
if word[-1] != 't': continue
if word+'i' in wordset: continue
simple = word + 'ed'
double = word + 'ted'
if simple in wordset:
print(word,simple)
count+=1
elif double in wordset:
print(word,double,'*')
countt+=1
print('simple=',count,' double=',countt)
如果不是以“it”结尾的话,您是否要计算一个“tt”字(“tt”in word') ( “它”)')? – jfs
我只需要以“it”结尾的单词。我在使用计数器计算双辅音时,以这些单词的“ed”结尾。 –
你只在t_中检查_ending。如果单词[-2:]!='它'不会'继续'更合适吗?什么是'如果word +'我'在wordset:继续'应该完成? –