diff --git a/10 一盘大棋/A02.py b/10 一盘大棋/A02 加入语言特性.py similarity index 100% rename from 10 一盘大棋/A02.py rename to 10 一盘大棋/A02 加入语言特性.py diff --git a/10 一盘大棋/A03.py b/10 一盘大棋/A03 Hacker.py similarity index 100% rename from 10 一盘大棋/A03.py rename to 10 一盘大棋/A03 Hacker.py diff --git a/11 概念认知/函数/A02.py b/11 概念认知/函数/1 全局变量.py similarity index 100% rename from 11 概念认知/函数/A02.py rename to 11 概念认知/函数/1 全局变量.py diff --git a/11 概念认知/函数/2 临时变量传递.py b/11 概念认知/函数/2 临时变量传递.py new file mode 100644 index 0000000..6e68d86 --- /dev/null +++ b/11 概念认知/函数/2 临时变量传递.py @@ -0,0 +1,30 @@ +import re +from cppy.cp_util import * + + +def extractwords(str_data): + pattern = re.compile('[\W_]+') + word_list = pattern.sub(' ', str_data).lower().split() + stop_words = get_stopwords() + return [w for w in word_list if not w in stop_words] + +def frequencies(word_list): + word_freqs = {} + for word in word_list: + word_freqs[word] = word_freqs.get(word, 0) + 1 + return word_freqs + +def sort(word_freq): + return sorted( word_freq.items(), key=lambda x: x[1], reverse=True ) + +def printall(word_freqs, n = 10 ): + for word, freq in word_freqs[ :n ]: + print(word, '-', freq) + + +if __name__ == "__main__": + txtcontent = read_file( testfilepath ) + word_list = extractwords( txtcontent ) + word_freqs = frequencies( word_list ) + word_sort = sort ( word_freqs ) + printall(word_sort) \ No newline at end of file diff --git a/11 概念认知/函数/A03.py b/11 概念认知/函数/3 连续调用.py similarity index 100% rename from 11 概念认知/函数/A03.py rename to 11 概念认知/函数/3 连续调用.py diff --git a/11 概念认知/函数/A04.py b/11 概念认知/函数/4 连续调用.py similarity index 100% rename from 11 概念认知/函数/A04.py rename to 11 概念认知/函数/4 连续调用.py diff --git a/11 概念认知/函数/A05.py b/11 概念认知/函数/5 常见风格.py similarity index 100% rename from 11 概念认知/函数/A05.py rename to 11 概念认知/函数/5 常见风格.py diff --git a/11 概念认知/对象化/A21.py b/11 概念认知/对象化/1 类对象.py similarity index 100% rename from 11 概念认知/对象化/A21.py rename to 11 概念认知/对象化/1 类对象.py diff --git a/11 概念认知/对象化/A22.py b/11 概念认知/对象化/2 字典对象.py similarity index 100% rename from 11 概念认知/对象化/A22.py rename to 11 概念认知/对象化/2 字典对象.py diff --git a/12 语言特性/内省/tf_93.py b/12 语言特性/内省.py similarity index 100% rename from 12 语言特性/内省/tf_93.py rename to 12 语言特性/内省.py diff --git a/12 语言特性/异步/82.py b/12 语言特性/异步.py similarity index 90% rename from 12 语言特性/异步/82.py rename to 12 语言特性/异步.py index 45c5c71..fcd7c7f 100644 --- a/12 语言特性/异步/82.py +++ b/12 语言特性/异步.py @@ -3,6 +3,7 @@ import aiofiles from collections import Counter from cppy.cp_util import * +########## 不太合适的一个场景 ###################### # # 协程 # diff --git a/12 语言特性/生成器/tf-28.py b/12 语言特性/生成器.py similarity index 100% rename from 12 语言特性/生成器/tf-28.py rename to 12 语言特性/生成器.py diff --git a/12 语言特性/装饰/tf-19B.py b/12 语言特性/装饰/自审装饰.py similarity index 100% rename from 12 语言特性/装饰/tf-19B.py rename to 12 语言特性/装饰/自审装饰.py diff --git a/12 语言特性/装饰/tf-19A.py b/12 语言特性/装饰/装饰器.py similarity index 100% rename from 12 语言特性/装饰/tf-19A.py rename to 12 语言特性/装饰/装饰器.py diff --git a/12 语言特性/递归/tf-08.py b/12 语言特性/递归/tf-08.py index bd228c8..552b341 100644 --- a/12 语言特性/递归/tf-08.py +++ b/12 语言特性/递归/tf-08.py @@ -1,7 +1,7 @@ import sys from cppy.cp_util import * -## 切分任务这个工作,可以统一为一个通用函数。做成一个生成器 +## 切分任务这个工作,可以统一为一个通用函数。做成一个生成器!! script_dir = os.path.dirname(os.path.abspath(__file__)) testfile = os.path.join(script_dir, 'test.txt') diff --git a/13 计算设备/任务平行分发/多线程1.py b/13 计算设备/任务平行分发/多线程.py similarity index 100% rename from 13 计算设备/任务平行分发/多线程1.py rename to 13 计算设备/任务平行分发/多线程.py diff --git a/13 计算设备/任务平行分发/多线程2.py b/13 计算设备/任务平行分发/抽象并发.py similarity index 83% rename from 13 计算设备/任务平行分发/多线程2.py rename to 13 计算设备/任务平行分发/抽象并发.py index 2485c0f..585178a 100644 --- a/13 计算设备/任务平行分发/多线程2.py +++ b/13 计算设备/任务平行分发/抽象并发.py @@ -2,7 +2,11 @@ import concurrent.futures from collections import Counter import cppy.cp_util as util -# 价值不大,就是多线程的一个表现,说明松耦合不如消息驱动的组件 +''' +concurrent.futures模块为Python中的并发编程提供了一个统一接口, +这个模块隐藏了低层次的线程和进程创建、同步和清理的细节,提供了一个更高层次的API来处理并发任务。 +当前版本推荐它与asyncio模块结合使用完成Python中的各种异步编程任务。 +''' class WordFrequencyAgent: def __init__(self, words): diff --git a/16 其它/异常/1 软件不能挂掉/tf-21.py b/16 其它/异常/1 软件不能挂掉.py similarity index 100% rename from 16 其它/异常/1 软件不能挂掉/tf-21.py rename to 16 其它/异常/1 软件不能挂掉.py diff --git a/16 其它/异常/2 时间停止在那一刻/tf-22.py b/16 其它/异常/2 时间停止在那一刻.py similarity index 100% rename from 16 其它/异常/2 时间停止在那一刻/tf-22.py rename to 16 其它/异常/2 时间停止在那一刻.py diff --git a/16 其它/异常/3 所有错误的应对/tf-23.py b/16 其它/异常/3 所有错误的应对.py similarity index 100% rename from 16 其它/异常/3 所有错误的应对/tf-23.py rename to 16 其它/异常/3 所有错误的应对.py