why does default dict count for the number of empty spaces in my list?
I calculate the number of times a character appears in a word using default dict. But My code also counts the number of empty spaces between the words aswell. So how do I calculate only the occurence of words and omit the empty spaces that occur in my words.
from collections import defaultdict
def count_var(word):
d = defaultdict(int)
for val in word:
d[val]+=1
return d
ct = count_var('big data examiner')
print ct
defaultdict(<type 'int'>, {'a': 3, ' ': 2, 'b': 1, 'e': 2, 'd': 1, 'g': 1, 'i': 2, 'm': 1, 'n': 1, 'r': 1, 't': 1, 'x': 1})