擅长:python、mysql、java
<p>您可以使用<code>get</code>使用简单的字典查找,因此,您可以处理<code>KeyError</code>:</p>
<pre><code>def translate(sentence): # the function start here
words = {'esta': 'is', 'la': 'the', 'en': 'in', 'gato': 'cat', 'casa': 'house', 'el': 'the'}
return ' '.join(words.get(x, '') for x in sentence.split())
</code></pre>