def count_words(string):
words = string.split()
word_count = {}
for word in words:
if word in word_count:
word_count[word] += 1
else:
word_count[word] = 1
return word_count
string = "I love programming. Programming is fun!" print(count_words(string))
标签:count,fun,word,string,单词,次数,words,字符串,love From: https://blog.51cto.com/u_16271069/8407082