擅长:python、mysql、java
<p>使用<code>chain.from_iterable</code>将列表转换为平面列表,然后将其馈送到<code>Counter</code></p>
<pre><code>from collections import Counter
from itertools import chain
c = [['a', 'b', 'c', 'd'], ['a', 'b'], ['a']]
Counter(chain.from_iterable(c))
# Counter({'a': 3, 'b': 2, 'c': 1, 'd': 1})
</code></pre>