我运行以下。all_possible 在文件顶部设置为 []。
def a_combination(input):
global current_char
for y in range(0,len(str(typed))):
working_int = int(list(str(input))[current_char])
print working_int
if (len(all_possible) == 0):
all_possible.append(digits_all[working_int-2][0])
all_possible.append(digits_all[working_int-2][1])
all_possible.append(digits_all[working_int-2][2])
else:
for x in range(0, len(all_possible)):
x = 3*x
## Duplicate to setup 3 of the same words in the list
all_possible.insert(x, all_possible[x])
all_possible.insert(x, all_possible[x])
## Now append the 1st possible character to the first version of the working string etc...
all_possible[x] = all_possible[x]+digits_all[working_int-2][0]
all_possible[x+1] = all_possible[x+1]+digits_all[working_int-2][1]
all_possible[x+2] = all_possible[x+2]+digits_all[working_int-2][2]
## Optimization - check after each stage for no-matches.
current_char += 1
打印所有可能
check_matches(all_possible)
print all_possible
def check_matches(input):
output = []
for possible_word in input[:]:
for real_word in word_dictionary:
if (normalise_word(real_word).startswith(possible_word)):
output.append(possible_word)
if (normalise_word(real_word) == possible_word):
print possible_word, 'is a perfect match with the dictionary.'
print output
all_possible = output
print all_possible
return all_possible
问题是它没有返回并在 a_combination 中设置 all_possible 的值。它在 check_matches 中打印处理后的值,但没有正确返回,这意味着 a_combination 打印了错误的内容(通过 normalise_word 之前的列表)。有任何想法吗?
山姆