所属专题:[Python社区](README.md)
 
## 问题
**输入:** 一个字符串`$ s $`,长度至多10000个字符。
**输出:** `$ s $`中每个单词出现的次数,各个单词以空格分隔,区分大小写,每个单词及次数占一行,且顺序不限。
**样例数据:**
```
We tried list and we tried dicts also we tried Zen
```
**样例输出:**
```
and 1
We 1
tried 3
dicts 1
list 1
we 2
also 1
Zen 1
```
 
## 背景知识
该问题涉及Python语言的核心数据类型之一——字典(dictionary)。详情请查阅ROSALIND网站上[关于该问题的背景说明](http://rosalind.info/problems/ini6/)。
 
## 解答
```python
def wd(s):
"""提取字符串s中以空格分隔的单词并统计单词频数"""
sl = list(s.split())
d = {x:sl.count(x) for x in sl}
return d
## --main--
with open("rosalind_ini6.txt", 'r') as f1:
s = f1.read()
d = wd(s)
with open("rosalind_ini6_out.txt", 'w') as f2:
for i,j in d.items():
f2.write(i + ' ' + str(j) + '\n')
```