I have a dictionary whereas the values are of string type. But I want to calculate the average per key whereas the empty string is a missing value. Here's my code just need a small twerk for it to work...with error : int() argument must be a string or a number, not 'list'
dic = {'E': ['1', '', '3'], 'M': ['2', '', '1']}
for k,n in dic.items():
k = [0]
n = [1]
D = {k: (int(n)) for k, n in dic.items() if n}
ave = {k:sum(D)/float(len(D))} if D else '-'
print ave
Expected output: {'E': 2, 'M': 1.5}