Can anyone explain me this ? This function takes a string and counts the frequency of each word and returns a dictionary with word,frequency. I dont understand how the dictionary gets data.
def count_words(text):
text = text.split()
words = {}
for i in text:
if i in words:
words[i] += 1
else:
words[i] = 1
return words
Aucun commentaire:
Enregistrer un commentaire