New course! Every coder should learn Generative AI!
Try a free lesson+ 2
Use a dictionary.
Loop over the letters
Check if the current letter is in the dict as a key. If not, then add the letter with an initial value of 1. If yes then increment the value by 1.
After the loop, output the dictionary.
You can also use a Counter() object from the collections class, passing it the string and then converting to a dict for output.
+ 2
hasnain siddiq89
First show your attempts.
What you had tried.
+ 1
Attempt
+ 1
The code you tried
+ 1
use len()
0
Hint:
Define a counter,define a item to find, iterate the objects and increase the counte every time, if the item is found.