This is my function:
def freq(*var):
from functools import reduce
from operator import getitem
for c,i in enumerate(reversed(var)):
d={k:0 for k in set(i)} if c==0 else {k:d for k in set(i)}
for row in zip(*var):
*k,last_k=row
reduce(getitem,k,d)[last_k]+=1
return d
var
argument would look like (['a','b','b','c'],['one','two','two','two'])
I am trying to return a nested dictionary that holds a frequency count. So result d
should look like:
{'a':{'one':1, 'two':0}, 'b':{'one':0, 'two':2}, 'c':{'one':0, 'two':1}}
However my function returns, which is wrong:
{'a': {'one': 1, 'two': 3}, 'b': {'one': 1, 'two': 3}, 'c': {'one': 1, 'two': 3}}
Any idea why?