我想运行此代码,以便它运行列表中的所有元素的函数。出于说明的目的,基本上它应该打印:For循环跳过一些东西! Python
'----------Possible Word:', possible_word
我列表中的所有项目。所以,如果我输入['p','r','s'],它将运行该打印3次,每个项目一次。我的代码在下面 - 当我运行它时,它只运行于p和s,而不是r,这真的很奇怪。有任何想法吗?
def check_matches(input):
print 'Input:', input
for possible_word in input:
print '----------Possible Word:', possible_word
valid = True
for real_word in word_dictionary:
possible_word_list = list(possible_word)
real_word_list = list(real_word)
print possible_word_list
print real_word_list
number_of_characters_to_check = len(possible_word_list)
for x in range(0, number_of_characters_to_check):
print possible_word_list[x] + real_word_list[x]
if (possible_word_list[x] != real_word_list[x]):
valid = False
if (valid == False):
input.remove(possible_word)
print all_possible
return input
在这个.py和顶部的变量启动还有其他函数,但我不想发布一个巨大的丑块,并认为这是所有相关的。如果你认为我应该发表其余的,请说。 –
所以我们将假设word_dictionary是全局列表权并且之前定义了? – Hamoudaq