擅长:python、mysql、java
<p><strong>如果需要:</strong></p>
<pre><code>c1 = [1, 6, 7, 10, 13, 28, 32, 41, 58, 63]
c2 = [[13, 17, 18, 21, 32], [7, 11, 13, 14, 28], [1, 5, 6, 8, 15, 16]]
c3 = [[13, 32], [7, 13, 28], [1,6]]
</code></pre>
<p><strong>下面是Python 2的解决方案:</strong></p>
<pre><code>c3 = [filter(lambda x: x in c1, sublist) for sublist in c2]
</code></pre>
<p>在Python 3中,{<cd1>}返回一个iterable而不是<code>list</code>,因此需要用<code>list()</code>来包装<code>filter</code>调用:</strong></p>
<pre><code>c3 = [list(filter(lambda x: x in c1, sublist)) for sublist in c2]
</code></pre>
<p><strong>说明:</strong></p>
<p>filter部分获取每个子列表的项并检查它是否在源列表c1中。
对c2中的每个子列表执行列表理解。</p>