From 44c1f9eb1ecf6156fb2718991a106af4d3838945 Mon Sep 17 00:00:00 2001 From: zj3D Date: Tue, 19 Mar 2024 13:51:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=A7=E4=BF=AE=E6=94=B94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{A02.py => A02 加入语言特性.py} | 0 10 一盘大棋/{A03.py => A03 Hacker.py} | 0 .../函数/{A02.py => 1 全局变量.py} | 0 .../函数/2 临时变量传递.py | 30 +++++++++++++++++++ .../函数/{A03.py => 3 连续调用.py} | 0 .../函数/{A04.py => 4 连续调用.py} | 0 .../函数/{A05.py => 5 常见风格.py} | 0 .../对象化/{A21.py => 1 类对象.py} | 0 .../对象化/{A22.py => 2 字典对象.py} | 0 .../{内省/tf_93.py => 内省.py} | 0 12 语言特性/{异步/82.py => 异步.py} | 1 + .../{生成器/tf-28.py => 生成器.py} | 0 .../装饰/{tf-19B.py => 自审装饰.py} | 0 .../装饰/{tf-19A.py => 装饰器.py} | 0 12 语言特性/递归/tf-08.py | 2 +- .../{多线程1.py => 多线程.py} | 0 .../{多线程2.py => 抽象并发.py} | 6 +++- .../tf-21.py => 1 软件不能挂掉.py} | 0 ...tf-22.py => 2 时间停止在那一刻.py} | 0 .../tf-23.py => 3 所有错误的应对.py} | 0 20 files changed, 37 insertions(+), 2 deletions(-) rename 10 一盘大棋/{A02.py => A02 加入语言特性.py} (100%) rename 10 一盘大棋/{A03.py => A03 Hacker.py} (100%) rename 11 概念认知/函数/{A02.py => 1 全局变量.py} (100%) create mode 100644 11 概念认知/函数/2 临时变量传递.py rename 11 概念认知/函数/{A03.py => 3 连续调用.py} (100%) rename 11 概念认知/函数/{A04.py => 4 连续调用.py} (100%) rename 11 概念认知/函数/{A05.py => 5 常见风格.py} (100%) rename 11 概念认知/对象化/{A21.py => 1 类对象.py} (100%) rename 11 概念认知/对象化/{A22.py => 2 字典对象.py} (100%) rename 12 语言特性/{内省/tf_93.py => 内省.py} (100%) rename 12 语言特性/{异步/82.py => 异步.py} (90%) rename 12 语言特性/{生成器/tf-28.py => 生成器.py} (100%) rename 12 语言特性/装饰/{tf-19B.py => 自审装饰.py} (100%) rename 12 语言特性/装饰/{tf-19A.py => 装饰器.py} (100%) rename 13 计算设备/任务平行分发/{多线程1.py => 多线程.py} (100%) rename 13 计算设备/任务平行分发/{多线程2.py => 抽象并发.py} (83%) rename 16 其它/异常/{1 软件不能挂掉/tf-21.py => 1 软件不能挂掉.py} (100%) rename 16 其它/异常/{2 时间停止在那一刻/tf-22.py => 2 时间停止在那一刻.py} (100%) rename 16 其它/异常/{3 所有错误的应对/tf-23.py => 3 所有错误的应对.py} (100%) 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