Вы можете использовать Counter
из collections
, чтобы сделать это очень эффективно:
In [161]: from collections import Counter
...:
...: count = Counter()
...:
...: lists = [['a','b','c'], ['a', 'c'], ['c', 'd']]
...:
...: for sublist in lists:
...: count += Counter(sublist)
...:
...: print(count)
Counter({'c': 3, 'a': 2, 'b': 1, 'd': 1})
Это "возможность в одну строку" с использованием встроенного python sum
:
In [163]: from collections import Counter
...: lists = [['a','b','c'], ['a', 'c'], ['c', 'd']]
...:
...: count = sum(map(Counter, lists), start=Counter())
...:
...: print(count)
Counter({'c': 3, 'a': 2, 'b': 1, 'd': 1})