擅长:python、mysql、java
<p>基本上,您不需要为列表1中的元素设置集合。如果检查列表1中的每个元组,它们的元素是否在列表2中的某个元组中。。。在</p>
<pre><code>list1 = [('We', 'all'), ('all', 'live'), ('live', 'in'), ('in', 'a'),
('a', 'yellow'), ('yellow', 'submarine.')]
list2 = [('A', 'live'), ('live', 'yellow'), ('yellow', 'submarine'),
('submarine', 'lifeform'), ('lifeform', 'in'), ('in', 'a'),
('a', 'sea.')]
Elements_set2 = set([item for tuple in list2 for item in tuple])
print [(i,v) for i,v in list1 if (i in Elements_set2 and v in Elements_set2 )]
</code></pre>
<p>由于您没有提供代码失败情况的详细信息,因此无法检查这个示例是否适用于失败的示例。在</p>