擅长:python、mysql、java
<p>您可以使用列表理解迭代列表并从字典中获取项目:</p>
<pre><code>output = [[item,ThePythons[item]] for item in query if item in ThePythons]
print output
</code></pre>
<p>输出:</p>
<pre><code>[['EI', 'Eric Idle'], ['JC', 'John Cleese']]
</code></pre>
<p>使用地图:</p>
<pre><code>map(lambda x: [x,ThePythons[x]] if x in ThePythons else [x,"Not found"], query)
</code></pre>