擅长:python、mysql、java
<p>考虑到与列表不同,元组<strong>是可散列的</strong>,因此需要将列表展平。一个简单的选项是使用<a href="https://docs.python.org/3/library/itertools.html#itertools.chain" rel="nofollow noreferrer">^{<cd1>}</a>,然后使用元组列表构建一个<code>Counter</code>:</p>
<pre><code>from itertools import chain
Counter(chain(*pairs))
</code></pre>
<p><b>输出</b></p>
^{pr2}$