我想運行此代碼,以便它運行列表中的所有元素的函數。出於說明的目的,基本上它應該打印: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