擅长:python、mysql、java
<p>我不会用单子来编字典。你正在把单词映射到它们的类型,所以编一本字典。</p>
<p>以下是我在不写整件事的情况下能给出的最大暗示:</p>
<pre><code>lexicon = {
'north': 'directions',
'south': 'directions',
'east': 'directions',
'west': 'directions',
'go': 'verbs',
'stop': 'verbs',
'look': 'verbs',
'give': 'verbs',
'the': 'stops',
'in': 'stops',
'of': 'stops',
'from': 'stops',
'at': 'stops'
}
def scan(sentence):
words = sentence.lower().split()
pairs = []
# Iterate over `words`,
# pull each word and its corresponding type
# out of the `lexicon` dictionary and append the tuple
# to the `pairs` list
return pairs
</code></pre>