擅长:python、mysql、java
<p>只需将<a href="https://docs.python.org/2/library/functions.html#filter" rel="nofollow noreferrer"><strong>filter</strong></a>内置函数替换为<a href="https://docs.python.org/2/library/functions.html#map" rel="nofollow noreferrer"><strong>map</strong></a>内置函数。你知道吗</p>
<p>并使用<a href="https://stackoverflow.com/questions/2068349/understanding-get-method-in-python">get</a>函数来获取<code>name</code>键的值,该函数在没有特定键的情况下不会给出键错误。你知道吗</p>
<pre><code>data = [{'name': "Joe", 'group': 1}, {'name': "Kirk", 'group': 2}, {'name': "Bob", 'group': 1}]
print map(lambda x: x.get('name'), data)
</code></pre>
<p>在Python3.x中</p>
<pre><code>print(list(map(lambda x: x.get('name'), data)))
</code></pre>
<p>结果:</p>
<pre><code>['Joe', 'Kirk', 'Bob']
</code></pre>
<hr/>
<p>使用<a href="https://docs.python.org/2/tutorial/datastructures.html#list-comprehensions" rel="nofollow noreferrer">List Comprehension</a>:</p>
<pre><code>print [each.get('name') for each in data]
</code></pre>