【发布时间】:2012-10-02 03:22:43
【问题描述】:
我需要帮助创建一个名为strcount(S) 的函数,该函数返回一个字典,其中单词作为键,单词出现的次数作为相应的值。输出应该是这样的:
strcount("a a a a b b")
{'a': 4, 'b': 2}
strcount("one")
{'one': 1}
sorted(strcount("this one and that one for one time").items())
[('and', 1), ('for', 1), ('one', 3), ('that', 1), ('this', 1), ('time', 1)]
【问题讨论】:
标签: python dictionary