我正在尝试将一个句子转录为一个类别列表(句子中每个单词一个),但不断得到“AttributeError:'NoneType'对象没有属性'append'”。有任何想法吗?
categories = {
'direction':["north","south","east","west","down","up","left","right","back"],
'verbs': ["go","stop","kill","eat"],
'stop_words': ["the","in","of","from","at","it"],
'nouns': ["door","bear","princess","cabinet"],
'numbers': ["0","1","2","3","4","5","6","7","8","9"]
}
sentence = "bear go left eat from cabinet 2."
words = sentence.split()
categorised_sentence = []
for word in words:
print "---Looking at word:", word
for category in categories.keys():
if word in categories.get(category):
print "===The category is:", category
categorised_sentence = categorised_sentence.append(category)
print "***categorised_sentence is: ", categorised_sentence
else:
print "hmm..."