Python itertools.permutations的无序版本
下面的程序使用Python itertools.permutations的无序版本,python,Python,下面的程序使用itertools.permutations从列表构造URL def url_construct_function(): for i in range(1, len(samplelist)): for item in list(permutations(samplelist, i)): 假设示例列表中有3项:a,b,c itertools.permutations提供了关于各种可能的有序组合的良好描述 a b c a、 b a、 c b、 a b、 c
itertools.permutations
从列表构造URL
def url_construct_function():
for i in range(1, len(samplelist)):
for item in list(permutations(samplelist, i)):
a
,b
,c
itertools.permutations
提供了关于各种可能的有序组合的良好描述
- a
- b
- c
- a、 b
- a、 c
- b、 a
- b、 c
- c、 a
- c、 b
我想让程序明白
a,b
和b,a
是相同的 itertools.compositions
的工作原理类似于itertools.permutations
,并执行您正在寻找的功能(以及名称所暗示的功能)
在组合中,与排列不同,顺序并不重要。所有这些都整齐地包含在。
itertools.compositions
中,而不是排列
可能…@schwobasegll,看起来像一个asnwerPhew,非常感谢@施沃巴塞格,我快疯了:)
from itertools import combinations
...
for item in list(combinations(samplelist, i)):
...
a
b
c
a, b
a, c
b, c