I need to make a function that reads a string and returns a dictionary where the keys are the words in the string and the values are how many times they occur.
This is what I tried:
def countWords(arg):
dic = {}
for i in agr:
if i in dic:
dic[i] += 1
else:
dic[i] = 1
return dic
Which only counts how many times a letter appears.
I thought of separating each word into a different position of a list first, but I'm not sure how to or even if that's the right way to go here..
What should I do?