且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-01-11 21:45:10

使用itertools.product

>>> import itertools
>>> s=[ [ 'a', 'b', 'c'], ['d'], ['e', 'f'] ]
>>> list(itertools.product(*s))
[('a', 'd', 'e'), ('a', 'd', 'f'), ('b', 'd', 'e'), ('b', 'd', 'f'), ('c', 'd', 'e'), ('c', 'd', 'f')]