import itertools
s="abcde"
def upto_n(s,n):
out = []
for i in range(1,n+1,1):
out += list(itertools.combinations(s, i))
return out
print upto_n(s,2)
print upto_n(s,3)
アウトプットPY3から入手itertools.product
(yield from
構文を使用して
[('a',), ('b',), ('c',), ('d',), ('e',), ('a', 'b'), ('a', 'c'), ('a', 'd'), ('a', 'e'), ('b', 'c'), ('b', 'd'), ('b', 'e'), ('c', 'd'), ('c', 'e'), ('d', 'e')]
[('a',), ('b',), ('c',), ('d',), ('e',), ('a', 'b'), ('a', 'c'), ('a', 'd'), ('a', 'e'), ('b', 'c'), ('b', 'd'), ('b', 'e'), ('c', 'd'), ('c', 'e'), ('d', 'e'), ('a', 'b', 'c'), ('a', 'b', 'd'), ('a', 'b', 'e'), ('a', 'c', 'd'), ('a', 'c', 'e'), ('a', 'd', 'e'), ('b', 'c', 'd'), ('b', 'c', 'e'), ('b', 'd', 'e'), ('c', 'd', 'e')]
はあなたのコードを共有してください。あなたが望む長さまで長さ1、2、3などの '順列'を生成する必要があるように見えます。これは 'for'ループで簡単に行うことができます。 – Julien
これは順列ではありません!私たちにあなたのコードと期待される出力と実際の出力を表示してください。 – alfasin