How to count occurrences of a word in a sentence [python]
Anonymous
text = open('data/file.txt', 'r') word_dict = {} for line in text: for word in line.split(): if word.lower() not in word_dict: word_dict[word.lower()] = 1 else: word_dict[word.lower()] += 1 for i,j in word_dict.items(): print(i + ' : ' + str(j))
Check out your Company Bowl for anonymous work chats.