输入一个字符串,字符串包含多个单词,单词间用一个空格分隔,字符串里没有任何标点符号。要求将该字符串中单词和单词出现的次数保存到字典中,并输出字典。
输入格式:
一个包含多个单词的字符串,单词间用一个空格分隔,字符串里没有任何标点符号。
输出格式:
输出一个字典。
输入样例:
在这里给出一组输入。例如:
life is short we need python we need python
输出样例:
在这里给出相应的输出。例如:
{'life': 1, 'is': 1, 'short': 1, 'we': 2, 'need': 2, 'python': 2}
答案:
list_my = input().split(' ')
number_my = {}
for x in list_my:
if x not in number_my:
number_my[x] = 1
else:
number_my[x] +=1
print(number_my)