+ 1
Counting letters in string
I have a question for python. How do I count repeated letters in a string. Apart from comparing each character with a-z? Thank you in advance.
6 Réponses
+ 8
//This is how you do
https://code.sololearn.com/cC7j33fV5sr4/?ref=app
+ 3
//welcome
+ 3
s = 'abracadabra'
print(*(f'{letter}: {s.count(letter)}' for letter in sorted(set(s))), sep='\n')
+ 2
Question unclear. How can you count the occurance of a letter, if you don't even know what letter it is ?
0
I meant this: You enter a random string for example “hello there!” and then I wish to know how to count the letters so 2x l, or 3x e.
0
Thank you!