The 365 Data Science team is proud to invite you to our own community forum. A very well built system to support your queries, questions and give the chance to show your knowledge and help others in their path of becoming Data Science specialists.
Ask
Anybody can ask a question
Answer
Anybody can answer
Vote
The best answers are voted up and moderated by our team

Python bootcamp – Dictionaries

Python bootcamp – Dictionaries

1
Vote
0
Answer

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

 
No answers so far.
×
LAST CHANCE
Ready to Learn Data Science?
50% OFF