我几乎完成了一个特定程序的编码。我只需要最后一块的帮助。 程序取一个单词,并将一个字母改为更接近目标单词。 改过的词一定存在于我得到的字典里。在
我的职能是:
def changeling(word,target,steps):
holderlist=[]
i=0
if steps==0 and word!=target:
return None
return holderlist
if len(word)!=len(target):
return None
if steps!=-1:
for items in wordList:
if len(items)==len(word):
i=0
if items!=word:
for length in items:
if i==1:
if items[1]==target[1] and items[0]==word[0] and items[2:]==word[2:]:
if items==target:
print "Target Achieved"
holderlist.append(items)
flatten_result(holderlist,target)
holderlist.append(changeling(items,target,steps-1))
elif i>0 and i<len(word)-1 and i!=1:
if items[i]==target[i] and items[0:i]==word[0:i] and items[i+1:]==word[i+1:]:
if items==target:
print "Target Achieved"
holderlist.append(items)
flatten_result(holderlist,target)
holderlist.append(changeling(items,target,steps-1))
elif i==0:
if items[0]==target[0] and items[1:]==word[1:]:
if items==target:
print "Target Achieved"
holderlist.append(items)
flatten_result(holderlist,target)
holderlist.append(changeling(items,target,steps-1))
elif i==len(word)-1:
if items[len(word)-1]==target[len(word)-1] and items[0:len(word)-1]==word[0:len(word)-1]:
if items==target:
print "Target Achieved"
holderlist.append(items)
holderlist.append(changeling(items,target,steps-1))
else:
return None
i+=1
return holderlist
我的助手功能是:
^{pr2}$在U函数中,也可以用U函数来表示我的结果列表。如何在换生灵中实现扁平化结果?到目前为止,我只能在pythonshell中完成。在
基本上
这样称呼它
word_chain(['love'], 'hate', your dict)
。如果您需要有关have_one_different_letter()
的帮助,请与我们联系。在相关问题 更多 >
编程相关推荐