Write a Python function called LetterCount() that takes a string as an argument and returns a dictionary of letter values.
Line:
print LetterCount("Abracadabra, Monsignor")
Should produce the result:
{'a': 5, 'c': 1, 'b': 2, 'd': 1, 'g': 1, 'i': 1, 'm': 1, 'o': 2, 'n': 2, 's': 1, 'r': 3}
I tried:
import collections c = collections.Counter('Abracadabra, Monsignor') print c print list(c.elements())
The answer I get is as follows
{'a': 4, 'r': 3, 'b': 2, 'o': 2, 'n': 2, 'A': 1, 'c: 1, 'd': 1, 'g': 1, ' ':1, 'i':1, 'M':1 ',':1's': 1, } ['A', 'a','a','a','a','c','b','b','d','g', and so on
Now with this import collection code c = collections.Counter ('Abracadabra, Monsignor'.lower ())
print c i get this {'a': 5, 'r': 3, 'b': 2, 'o': 2, 'n': 2, 'c: 1,' d ': 1,' g ' : 1, '': 1, 'i': 1, ',': 1's': 1,}
but the answer should be like this {'a': 5, 'c': 1, 'b': 2, 'd': 1, 'g': 1, 'i': 1, 'm': 1, 'o ': 2,' n ': 2,' s': 1, 'r': 3}