代码点读机 / Python / itertools

itertools Python · 常用模块

专门生成迭代器和排列组合的工具包。

怎么用

import itertools

小例子

import itertools
print(list(itertools.permutations([1, 2])))

运行结果

[(1, 2), (2, 1)]

提醒:省得自己写嵌套循环。

官方文档:https://docs.python.org/zh-cn/3/library/itertools.html

在代码里遇到不认识的词?打开代码点读机,点一下就懂 → ← Python全部词条