python counter nested dictionary
import collections
a = collections.defaultdict(collections.Counter)
inf = [('fruit','apple'),('car','truck'),('fruit','banana'),('fruit','banana')]
for category,item in inf:
a[category][item] = a[category][item] + 1
#print(a)
#{'fruit': Counter({'banana': 2, 'apple': 1}), 'car': Counter({'truck': 1})})