python数据分析

从键盘输入一个英文句子或单词组成的字符串,可以不包含标点符号,但单词之间要用空格分开。将句子中单词以及出现的频次分别作为key和value保存在字典中,并输出。(提示:字符串的split方法可以将字符串转成列表,列表的count方法可以统计列表元素的频次)
输入样例:
I am Chinese student and I am studying in Henan Agricultural University.
输出样例:
I 2
am 2
Chinese 1
student 1
and 1
studying 1
in 1
Henan 1
Agricultural 1
University 1

sentence = input("")

words = sentence.replace(".", "").replace(",", "").split()

word_count = {}
for word in words:
    if word not in word_count:
        word_count[word] = 1
    else:
        word_count[word] += 1

for word, count in word_count.items():
    print(word, count)