小编Ian*_*vis的帖子

Python中一组列表的所有可能排列

在Python中,我有一个n列表的列表,每个列表都有可变数量的元素.如何创建包含所有可能排列的单个列表:

例如

[ [ a, b, c], [d], [e, f] ]
Run Code Online (Sandbox Code Playgroud)

我想要

[ [a, d, e] , [a, d, f], [b, d, e], [b, d, f], [c, d, e], [c, d, f] ]
Run Code Online (Sandbox Code Playgroud)

注意我事先不知道n.我认为itertools.product是正确的方法,但它要求我提前知道参数的数量

python list permutation

45
推荐指数
3
解决办法
2万
查看次数

标签 统计

list ×1

permutation ×1

python ×1