擅长:python、mysql、java
<p>为<code>s1</code>查找<code>id2</code>中的每个<code>tuple</code>在<code>s2</code>中的所有id上设置<code>set</code></p>
<pre><code>s1 = {(1, 'string111'), (2, 'string222')}
s2 = {(2, 'string333'), (3, 'string444')}
id2 = {x[0] for x in s2} # all the id in s2
filtered = list(filter(lambda x: x[0] in id2, s1)) # lookup id2 and filter
print(filtered) # => [(2, 'string222')]
</code></pre>
<p>非FP版本</p>
<pre><code>id2 = {x[0] for x in s2}
ret = set()
for x in s1:
if x[0] in id2:
ret.add(x)
print(ret) # => {(2, 'string222')}
</code></pre>