+ 6

How to count the frequency of a letter in a word in python??

2nd Aug 2019, 12:36 PM
Siddhi Jain
Siddhi Jain - avatar
13 ответов
+ 6
word = 'mississippi' for letter in set(word): print(letter, '=', word.count(letter))
2nd Aug 2019, 4:26 PM
HonFu
HonFu - avatar
+ 12
s=input() for i in range(len(s)): if s[i] not in s[:i]: print(s[i]+"="+s.count(s[i]))
5th Aug 2019, 3:36 AM
🐆 Janaki Ramudu 🅓🅞🅝 🇮🇳
🐆 Janaki Ramudu 🅓🅞🅝   🇮🇳 - avatar
+ 7
word = 'googlegooglehalohalo' print(",".join(set(list(map((lambda x:x+"="+str(word.count(x))),word)))))
2nd Aug 2019, 4:42 PM
Sarthak
Sarthak - avatar
+ 4
Mateusz R It won't work. Try replacing variable 'str' to 'txt' or else. It will work.
2nd Aug 2019, 4:23 PM
Sarthak
Sarthak - avatar
+ 4
def count(word): result = dict() for line in word: local = word.count(line) result[line] = local return result print(count("google"))
5th Aug 2019, 8:52 AM
Jennifer Erikson
Jennifer Erikson - avatar
+ 4
Why r u going for some tough solutions? Wanna Make it easy see here!!1 Letter Frequency Problem -- text=input() letter=input() count=0 for i in range(0,len(text)): if letter==text[i]: count+=1 fre=int((count/len(text))*100) print(fre)
28th Feb 2021, 8:35 AM
Bishwanath Kumar
Bishwanath Kumar - avatar
+ 2
I extended my code with the functionality you want. Take a look Siddhi.
2nd Aug 2019, 4:20 PM
Mateusz R
Mateusz R - avatar
+ 1
str = "SoloLearn" freq = {} for i in str: if i in freq: freq[i] += 1 else: freq[i] = 1 print ("Frequency :\n " + str(freq))
2nd Aug 2019, 12:50 PM
αιɱαɳ
αιɱαɳ - avatar
+ 1
This is one of possible solutions: https://code.sololearn.com/cz2fEt6X87D9/#py
2nd Aug 2019, 12:52 PM
Mateusz R
Mateusz R - avatar
+ 1
'mississippi'.count('i')
2nd Aug 2019, 1:54 PM
HonFu
HonFu - avatar
+ 1
I want the output like Input string :google Output: g =2 o=2 l=1 e=1
2nd Aug 2019, 4:11 PM
Siddhi Jain
Siddhi Jain - avatar
0
In c I use the array method to find the frequency... But in python array is not native you can use the numpy library for that ... Hope it will help
11th Sep 2019, 6:07 AM
Nagaraj P
Nagaraj P - avatar
0
Here my code. I tried to do in a beginner way ( very straightforward ) a=input() b=input() c=len(a) cont = a.count(b) volte = int((cont/c)*100) print(volte)
19th Oct 2022, 10:46 AM
stefano sartori
stefano sartori - avatar