1import collections
2a = collections.defaultdict(collections.Counter)
3inf = [('fruit','apple'),('car','truck'),('fruit','banana'),('fruit','banana')]
4for category,item in inf:
5 a[category][item] = a[category][item] + 1
6#print(a)
7#{'fruit': Counter({'banana': 2, 'apple': 1}), 'car': Counter({'truck': 1})})