Created
June 20, 2016 11:29
-
-
Save diallobakary4/332660ae3d4c8bd0c882bbbad8c9b32f to your computer and use it in GitHub Desktop.
Count the number of each word in a text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# scrip that print the number of time a word appear in a text | |
#import the text file and read it | |
test = open("test list of word r.txt", 'r'); | |
text = test.read(); | |
#build a list of the words in the text | |
listOfWord = text.split() | |
# dictionnay that will contain the words | |
# and the number of times they appear in the string | |
dico = {}; | |
#dico building | |
for words in listOfWord : | |
dico [words]= text.count(words) | |
# printing the words and the numbers of time they appear | |
for word in dico : | |
print(word), | |
print (dico[word]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment