首页
关于
Search
1
用 Typecho 搭建一个极简个人站点的完整记录
23 阅读
2
周末去了趟老城区,拍了一些快门
10 阅读
3
把书房改成一间能待住的房间
6 阅读
4
欢迎使用 Typecho
5 阅读
5
一次 MySQL 慢查询的完整排查过程
5 阅读
默认分类
技术笔记
生活随笔
摄影
读书
资源分享
登录
Search
标签搜索
性能
家居
日常
图片
前端
音乐
复盘
MySQL
改造
扫街
独立开发
免费
工具
技巧
Python
书评
毛姆
胶片
渐行渐远渐无书
累计撰写
11
篇文章
累计收到
16
条评论
首页
栏目
默认分类
技术笔记
生活随笔
摄影
读书
资源分享
页面
关于
搜索到
1
篇与
Python
的结果
2026-10-01
Python 里我常用但同事常忘的 12 个写法
攒下来的小抄,多数是 itertools 和标准库里的边角料。1. itertools.pairwise 取代手滑下标from itertools import pairwise for a, b in pairwise(rows): if b['ts'] - a['ts'] > 60: print('gap', a['id'], b['id'])2. collections.Counter 的算术total = Counter(x) + Counter(y) # 并 only_a = (Counter(x) - Counter(y)) # 差3. str.removeprefix 而不是 [3:]name = raw.removeprefix('user:')4. 一行读完整个文件再处理with open(p, encoding='utf-8') as f: lines = [ln.rstrip() for ln in f if ln.strip()]5. enumerate(start=1) 处理行号其余 7 条(functools.cache、zip(*rows) 转置、dataclass(slots=True)、Path.glob 排序坑、typing.assert_never 穷尽检查、tempfile.NamedTemporaryFile(delete_on_close=False)、os.process_cpu_time_ns)另开一篇写。
2026年10月01日
3 阅读
0 评论
0 点赞