|
| 1 | +#-*- coding: UTF-8 -*- |
| 2 | +import collections |
| 3 | +import os |
| 4 | + |
| 5 | +text = ''' |
| 6 | +The Zen of Python, by Tim Peters |
| 7 | +
|
| 8 | +
|
| 9 | +Beautiful is better than ugly. |
| 10 | +Explicit is better than implicit. |
| 11 | +Simple is better than complex. |
| 12 | +Complex is better than complicated. |
| 13 | +Flat is better than nested. |
| 14 | +Sparse is better than dense. |
| 15 | +Readability counts. |
| 16 | +Special cases aren't special enough to break the rules. |
| 17 | +Although practicality beats purity. |
| 18 | +Errors should never pass silently. |
| 19 | +Unless explicitly silenced. |
| 20 | +In the face of ambxiguity, refuse the temptation to guess. |
| 21 | +There should be one-- and preferably only one --obvious way to do it. |
| 22 | +Although that way may not be obvious at first unless you're Dutch. |
| 23 | +Now is better than never. |
| 24 | +Although never is often better than *right* now. |
| 25 | +If the implementation is hard to explain, it's a bad idea. |
| 26 | +If the implementation is easy to explain, it may be a good idea. |
| 27 | +Namespaces are one honking great idea -- let's do more of those! |
| 28 | +''' |
| 29 | + |
| 30 | +text_cn = ''' |
| 31 | +
|
| 32 | +来自管理员童鞋的回复:可以自己定义哈,主要是实现函数的功能 |
| 33 | +完成时可以自己写一些测试的参数,检验自己的函数功能是否正确 |
| 34 | +
|
| 35 | +''' |
| 36 | + |
| 37 | +def stats_text_en (text): #sort English words by the frequency. |
| 38 | + |
| 39 | + text = text.replace('--', '') |
| 40 | + text = text.replace('!', '') |
| 41 | + text = text.replace('*', '') |
| 42 | + text = text.split() |
| 43 | + |
| 44 | + return collections.Counter(text) |
| 45 | + |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | +def stats_text_cn (text): #sort Chinese words by the frequency. |
| 50 | + |
| 51 | + text = text.replace(':', '') |
| 52 | + text = text.replace(',', '') |
| 53 | + text = text.replace('\n', '') |
| 54 | + #text = text.replace('*', '') |
| 55 | + print ('first char:') |
| 56 | + print (text[0]) |
| 57 | + |
| 58 | + text_split = [] |
| 59 | + |
| 60 | + for i in range(len(text)): |
| 61 | + text_split.append(text[i]) |
| 62 | + |
| 63 | + #text = text.split() |
| 64 | + |
| 65 | + return collections.Counter(text) |
| 66 | + |
| 67 | +print(stats_text_cn(text_cn)) |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | + |
0 commit comments