我正在開發一個定義測試程序(您輸入單詞,它們的部分演講內容和每個同義詞,然後測試它們)。問題我已經是與獲取字部分:Python:追加到列表
def get_word(): # this is in another function, that's why it is indented
import easygui as eg
word_info = eg.multenterbox(msg = 'Enter in the following information about each word.'
, title = 'Definition Tester'
, fields = ['Word: ', 'Part of Speech: ', 'Synonyms (separated by spaces): ']
, values = []
)
return word_info
for i in range(n):
my_list = get_word()
print my_list # for testing
word, pOS, synonyms = my_list[0], my_list[1], my_list[2]
word = word.capitalize()
synonyms = synonyms.split(', ')
words_list += word
print word # for testing
test_dict[word] = [pOS, synonyms]
print words_list # for testing
但是,words_list
結束了list(word)
功能應用到他們之後是字(S)---我不知道爲什麼。
例如:如果唯一的單詞是'單詞',words_list
原來是['w', 'o', 'r', 'd']
。如果有兩個詞('狗','貓'),words_list
原來是['d', 'o', 'g', 'c', 'a', 't']
。 這是我的輸入(到get_word()
):單詞:'myword',詞性:'n',同義詞:'同義詞,定義'。
這是輸出我得到:
['myword', 'n', 'synonym, definition']
Myword
['M', 'y', 'w', 'o', 'r', 'd'] # Why does this happen?
這是唯一的事情錯了我的計劃......如果我能得到關於如何解決這個問題,什麼是錯的一些投入,這將是更讚賞。謝謝!
你能打印'word_info'嗎? –
'my_list'等於'word_info',因爲函數'get_word()'返回'word_info','my_list'被設置爲返回值('my_list = get_word()')。 –