Hey Folks!
Good Day...
Today I Practiced one of the Frequently asked Question that is nothing but "To find the frequency of characters in a given string"
Disclaimer : Eventhough there are so many inbuilt methods or ways to find the solution for this problem in python . As a beginner / budding developer , I practiced using loop for better understanding about loops and concepts.
Let's get into Logic first:
By default we cannot change the string in python because Strings are Immutable in Python.So that I changed it to list , it is a basically a array in python . We can loop through it and change the characters we want.
By human brain logic , let's say "ebenezer" in this string the letter "e" is appeared four times and "b" appeared one time .
We need to run the loop and check the letter "e" is appeared or not , if it is appeared we have to increment the count.
But there is one difficulties after the second letter "b" again letter "e" will come and compare with other letters. If this thing happens the output will looks like e 4 , b 1 , e 3 ...
For that we have to change the already appeared letter to any unique characters like ! , @, # .
Code:
Output:
That's all about this Blog . See you in my next Blog...


Top comments (0)