擅长:python、mysql、java
<p>根据ex48指令,可以为每种单词创建一些列表。这是第一个测试用例的样本。返回的值是一个元组列表,因此可以为给定的每个单词追加到该列表中。</p>
<pre><code>direction = ['north', 'south', 'east', 'west', 'down', 'up', 'left', 'right', 'back']
class Lexicon:
def scan(self, sentence):
self.sentence = sentence
self.words = sentence.split()
stuff = []
for word in self.words:
if word in direction:
stuff.append(('direction', word))
return stuff
lexicon = Lexicon()
</code></pre>
<p>他指出,数字和异常的处理方式是不同的。</p>