擅长:python、mysql、java
<p>当然可以用函数来实现。您可以使用<code>filter</code><a href="http://docs.python.org/2/library/functions.html#filter" rel="nofollow">builtin function</a>:</p>
<pre><code>new_list = filter(lambda foo: foo.location == 2, foos)
</code></pre>
<p>但更普遍的“Python式”方法是使用<a href="http://docs.python.org/2/tutorial/datastructures.html#list-comprehensions" rel="nofollow">list comprehensions</a></p>
^{pr2}$