Is there a way to get how many times a letter is repeated in a string, how? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Is there a way to get how many times a letter is repeated in a string, how?

Example : aasdf Output : a is repeated 2 times

4th Jan 2021, 4:33 PM
Amit Kumar
Amit Kumar - avatar
9 Answers
+ 8
# You can use the string method count string.count(value)
4th Jan 2021, 4:44 PM
noteve
noteve - avatar
+ 6
Yes, 《 Nicko12 》is right .I didn't know about that string function.Thanks to 《Nicko12 》I came to know about that function.
4th Jan 2021, 4:52 PM
The future is now thanks to science
The future is now thanks to science - avatar
+ 5
Amit Kumar Sorry but I think he is trying to give you hints and clues to use for loop then it is up to you how you will make it count the characters. The string method is the same with for loop anyway, When you use string.count(value), "for loop" is also happening in the background. Hope this makes sense🙂
4th Jan 2021, 4:48 PM
noteve
noteve - avatar
+ 4
Yes it's possible.
4th Jan 2021, 4:35 PM
The future is now thanks to science
The future is now thanks to science - avatar
+ 2
《 Nicko12 》 thank you string.count() helped. Also I know that I have to use loop and was looking for the function
4th Jan 2021, 4:50 PM
Amit Kumar
Amit Kumar - avatar
+ 2
check out this solution using for loop to a particular character in a string https://code.sololearn.com/cd4x24vejagU/?ref=app
4th Jan 2021, 6:32 PM
Kingsley Aham
Kingsley Aham - avatar
+ 2
There are many ways to skin a cat
5th Jan 2021, 11:02 AM
Sonic
Sonic - avatar
+ 1
4th Jan 2021, 4:37 PM
Amit Kumar
Amit Kumar - avatar
+ 1
Zatch bell lmao dude I think you misread my question 😂
4th Jan 2021, 4:46 PM
Amit Kumar
Amit Kumar - avatar