0
How can we determine the occurence of each word in a string using python
No inbuilt function to be used
2 odpowiedzi
+ 1
Maintain a empty dictionary and variable count initialized to 0 ,loop over each character in a string , check if that character is in dictionary or not, if it is not there increment count by 1 for indicating it's first occurence and insert key as alphabet and and value as count ,if character is in dictionary ,store that dictionary character value to a variable like
a=dictionary[character]
increment the value
a+=1
insert the new value back into dictionary
dictionary[character]=a
0
You can also try collection for Easy way
from collections import Counter
S = Counter(yourString)
Print(S)
This will help