空白文字を含まない文字列内の単語を検索する関数を作成しようとしています: 'Daysaregood'。 私は魔法使いの魔法使いを使用して、既に反復された手紙に基づいてリストと比較することによって単語が存在するかどうかを見つけるまで、すべての文字を繰り返します。 と、これは私が試したものです:私が望むようにスクリプトが実行さPython:空白文字なしの文字列内の単語を見つける
import enchant
import time
fulltext =[]
def work(out):
if len(out)>0:
word = ''
wd = ""
# iterate for every Letter
for i in out:
word = word + i
print word
d = enchant.Dict('en_US')
# a list of words to compare to
list = d.suggest(word.title())
print list
#check if word exists
if word.title() in list :
print 'Word found'
wd = word
else:
print 'Word not found'
print '\n'+wd
fulltext.append(str(wd))
time.sleep(2)
work(out[len(wd):])
else:
print '\n fulltext : '
print fulltext
word="Daysaregood"
work(word)
今、このテキストに、私はこのようなリストを得る: [「日」、「ある」、「良いです」]。 しかし、私は 'spaceshuttle'のようなものを試してみると、この関数は 'space'と混同されて 'shuttle'の 's'をスティールします。 ['spaces'、 'hut'、 't'、l '、' e ']。 私の目標は、すべての単語を単独で返し、リストに格納することです。 何か助けていただければ幸いです。