大家好,我这里有一小段代码让我很头疼.在这个函数中,我定义了一个名为word的列表,突然之间列表变成了一个字符串.我不知道这怎么可能:
def find_best_shift(wordlist, text):
words = []
word = []
for x in range(0, 27):
apply_shift(text, x)
for character in text:
print (type(word))
if (character in ALPHABET) or (character in alphabet):
word.append(character)
else:
wor = ''.join(word)
words.append(wor)
word = []
for word in words:
y = is_word(wordlist, word)
if y == True:
return x
Run Code Online (Sandbox Code Playgroud)
你们注意到了print语句print(type(word)).使用此语句,我得到以下输出:
<class 'list'>
<class 'list'>
<class 'list'>
<class 'list'>
<class 'list'>
<class 'list'>
<class 'list'>
<class 'list'>
<class 'list'>
<class 'list'>
<class …Run Code Online (Sandbox Code Playgroud) python ×1