-2
我用Python寫一個代碼從用戶那裏獲取智能輸入和我使用該詞彙。我正在使用一個不同的函數來將列表元組保存在一個列表中,但是列表並沒有像我期望的那樣被更新。我正在更新我的python程序中的列表,但它沒有按預期更新。請指出錯誤
我的代碼是:
directions = ['north', 'south', 'west', 'east', 'forward', 'down', 'up', 'left', 'right', 'back', 'n', 'w', 's', 'e']
verbs = ['go', 'stop', 'eat', 'attack', 'kill']
nouns = ['Jack', 'John', 'Keshav', 'Saket', 'door', 'princess', 'bat', 'bear']
StopWords = ['the', 'in', 'is', 'of', 'from', 'at', 'it']
GetName = raw_input("Enter your name\t")
word_definition = []
def function(GetName,word_definition):
words = GetName.split()
for i in words:
if i in directions:
word_definition.append(('Direction',i))
elif i in verbs:
word_definition.append(('Verb',i))
elif i in nouns:
word_definition.append(('Noun',i))
elif i in StopWords:
word_definition.append(('Stop Word',i))
else:
word_definition.append(('Unknown Type',i))
return word_definition
word_definition = (GetName, word_definition)
print word_definition
我輸入 「我的名字是凱沙夫」
我期望列表爲[( '未知類型', '我的'),('未知更新類型 ' '名'),( '停止字', '是'),( '名詞', '凱沙夫')]
相反,輸出作爲未來:
(' 我的名字是凱沙夫',[])
請指出可能的錯誤。 任何幫助將不勝感激。
看起來你從來沒有所謂的功能。 –