Hi there! I have a question for performing letter count using dictionary. My code is exactly the same as Giles’, however the letter count seems to be inaccurate. Could you enlighten me on why is this the case?
essay = '''I love curry laksa very much. In fact, it is my most favourite food ever!
What about other food? You asked. Well, I also love Pizza, Ramen! Yummm!'''
count = {}
for letter in essay:
count[letter.lower()] = count.get(letter,0)+1
print(count)
>>> {'i': 2, ' ': 27, 'l': 6, 'o': 12, 'v': 5, 'e': 10, 'c': 3, 'u': 6, 'r': 1, 'y': 1,
'a': 10, 'k': 2, 's': 5, 'm': 7, 'h': 3, '.': 2, 'n': 2, 'f': 4, 't': 7, ',': 3,
'd': 3, '!': 3, '\n': 1, 'w': 1, 'b': 1, '?': 1, 'p': 1, 'z': 2}
It is very clear that there are more than 2 “i” in the “essay”, tho the output says 2. I can’t really wrap my head around this.
Looking forward to your answer,
Min