Last answered:

19 Mar 2021

Posted on:

29 Jul 2020

1

Python bootcamp - Dictionaries

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
 
1 answers ( 0 marked as helpful)
Instructor
Posted on:

19 Mar 2021

0

Hi Min,
sorry for the late response. If the question is still unresolved would you be able to ask the question in the corresponding lecture of the course? Thank you!

Best,
365 Eli

Submit an answer