Count letters | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Count letters

I need to count how many times a letter appears in a word. For example, "hello" --> "l" = 2, "o" --> 1 etc... Can you please tell me the code logic

9th Jun 2021, 8:26 PM
Adilet Kambarov
Adilet Kambarov - avatar
3 Answers
+ 2
I did a dict-comprehension with the .count() method as my value 👍 but to rkk 's point, it is easier to help you, by you showing us, how to help you, we need to see your logic too.
9th Jun 2021, 8:47 PM
Steven M
Steven M - avatar
+ 1
Okay. Where's your attempt? edit: Code logics, make a map. traverse each letter. If the letter is in map then increment its frequency else add new entry of the letter to the map. sounds complex but it's easy and intuitive. Happy coding.
9th Jun 2021, 8:30 PM
Rohit
0
there's a built-in utility class ready to return a dict like object in the module 'collections' ;P https://docs.python.org/3/library/collections.html
9th Jun 2021, 11:27 PM
visph
visph - avatar