+ 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.

31st Jan 2020, 6:25 PM
Tom
Tom  - avatar
6 Respuestas
31st Jan 2020, 6:47 PM
Sudarshan Rai
Sudarshan Rai - avatar
+ 3
//welcome
31st Jan 2020, 6:48 PM
Sudarshan Rai
Sudarshan Rai - avatar
+ 3
s = 'abracadabra' print(*(f'{letter}: {s.count(letter)}' for letter in sorted(set(s))), sep='\n')
31st Jan 2020, 7:20 PM
HonFu
HonFu - avatar
+ 2
Question unclear. How can you count the occurance of a letter, if you don't even know what letter it is ?
31st Jan 2020, 6:45 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
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.
31st Jan 2020, 6:47 PM
Tom
Tom  - avatar
0
Thank you!
31st Jan 2020, 6:48 PM
Tom
Tom  - avatar