【发布时间】:2021-12-05 17:21:43
【问题描述】:
我的输出以大括号和字典样式出现在一行中,但我希望它以不同的方式格式化。例如:如果输入是"hello i am"
输出:
am : 1
hello : 1
i : 1
这是我的代码:
def word_count(q):
i = dict()
j = q.split()
j.sort()
for word in j:
if word in i:
i[word] += 1
else:
i[word] = 1
return i
sent = input( ).lower()
x = word_count(q)
【问题讨论】:
-
输出中的顺序是否重要,或者行的顺序可以是什么?
标签: python python-3.x dictionary type-conversion output