Using Counter with list of lists
from itertools import chain
from collections import Counter
seq = [['a','b','a','c'], ['a','b','c','d']]
c = Counter(chain(*seq))
print(c)
Counter({'a': 3, 'b': 2, 'c': 2, 'd': 1})
Using generator expression with set
:
>>> from collections import Counter
>>> seq = [['a','b','a','c'], ['a','b','c','d']]
>>> Counter(x for xs in seq for x in set(xs))
Counter({'a': 2, 'c': 2, 'b': 2, 'd': 1})
Responding to the comment, Without generator expression:
>>> c = Counter()
>>> for xs in seq:
... for x in set(xs):
... c[x] += 1
...
>>> c
Counter({'a': 2, 'c': 2, 'b': 2, 'd': 1})
The following code snippet brings all the occurrences' count of the list's item, hope this will help.
from collections import Counter
_list = [['a', 'b', 'c', 'd', 'a'],['a', 'a', 'g', 'b', 'e', 'g'],['h', 'g', 't', 'y', 'u']]
words = Counter(c for clist in _list for c in clist)
print(words)