class alexicon(object):
def __init__(self):
self.directions = ['north', 'south', 'west', 'east', 'up', 'down']
self.items = []
def scan(self, words):
self.word = words.split()
# direction
self.direction_word = [i for i in self.word if i in self.directions]
self.direction_list = []
for x in self.direction_word:
self.direction_list.append(('direction', '%s' %(x)) )
if self.direction_list != []:
self.items.extend(self.direction_list)
else:
pass
return self.items
lexicon = alexicon()
result = lexicon.scan('north')
print result
Почему результат печати получает «Нет»?Как я могу получить список предметов?Но если я распечатаю lexicon.items, я могу получить правильный список (в этом списке есть элементы).