我有一个清单(可能是任何长度)......
iterable = [A,B,C,D,E,F] # length = 6 in this example
我想获得此列表中包含所有元素的所有可能分组(上例中为6个)并输出一组集...
{{{A,B,C,D,E,F}}
{{A}, {B,C,D,E,F}}
{{A}, {B}, {C,D,E,F}}
{{A}, {C}, {B,D,E,F}}
{{A}, {D}, {B,C,E,F}}
{{A}, {E}, {B,C,D,F}}
{{A}, {F}, {B,C,D,E}}
{{A}, {B,C}, {D,E,F}}
{{A}, {B,D}, {C,E,F}}
{{A}, {B,E}, {C,D,F}}
{{A}, {B,F}, {C,D,E}}
{{A}, {C,D}, {B,E,F}}
{{A}, {C,E}, {B,D,F}}
{{A}, {C,F}, {B,D,E}}
{{A}, {D,E}, {B,C,F}}
{{A}, {D,F}, {B,C,E}}
{{A}, {E,F}, {B,C,D}}
{{A}, {B}, {C}, {D,E,F}}
{{A}, {B}, {D}, {C,E,F}}
{{A}, {B}, {E}, {C,D,F}}
{{A}, {B}, {F}, {C,D,F}}
{{A}, {C}, {D}, {B,E,F}}
{{A}, {C}, {E}, {B,D,F}}
{{A}, {C}, {F}, {B,D,E}}
{{A}, {D}, {E}, {B,C,F}}
{{A}, {D}, {F}, {B,C,E}}
{{A}, {E}, {F}, {B,D,E}}
{{A}, {B,C}, {D}, {E,F}}
{{A}, {B,C}, {E}, {D,F}}
{{A}, {B,C}, {F}, {D,E}}
{{A}, {B,D}, {C}, {E,F}}
{{A}, {B,D}, {E}, {C,F}}
{{A}, {B,D}, {F}, {C,E}}
{{A}, {B,E}, {C}, {D,F}}
{{A}, {B,E}, {D}, {C,F}}
{{A}, {B,E}, {F}, {C,D}}
{{A}, {B,F}, {C}, {D,E}}
{{A}, {B,F}, {D}, {C,E}}
{{A}, {B,F}, {E}, {C,D}}
{{A}, {C,D}, {B}, {E,F}}
{{A}, {B}, {C}, {D}, {E,F}}
{{A}, {B}, {C}, {E}, {D,F}}
{{A}, {B}, {C}, {F}, {D,E}}
...
{{A}, {B}, {C}, {D}, {E}, {F}}
{{B}, {A,C,D,E,F}}
{{B}, {A,C}, {D,E,F}}
{{B}, {A,D}, {C,E,F}}
{{C}, {A,B,D,E,F}}
{{D}, {A,B,C,E,F}}
{{E}, {A,B,C,D,F}}
{{F}, {A,B,C,D,E}}
{{A,B}, {C,D,E,F}}
{{A,C}, {B,D,E,F}}
{{A,D}, {B,C,E,F}}
{{A,E}, {B,C,D,F}}
{{A,F}, {B,C,D,E}}
{{B,C}, {A,D,E,F}}
{{B,D}, {A,C,E,F}}
{{B,E}, {A,C,D,F}}
{{B,F}, {A,C,D,E}}
{{C,D}, {A,B,E,F}}
{{C,E}, {A,B,D,F}}
{{C,F}, {A,B,D,E}}
{{D,E}, {A,B,C,F}}
{{D,F}, {A,B,C,E}}
{{E,F}, {A,B,C,D}}
{{A,B,C}, {D,E,F}}
{{A,B,D}, {C,E,F}}
{{A,B,E}, {C,D,F}}
{{A,B,F}, {C,D,E}}
{{A,C,D}, {B,E,F}}
{{A,C,E}, {B,D,F}}
{{A,C,F}, {B,D,E}}
{{A,D,E}, {B,C,F}}
{{A,D,F}, {B,C,E}}
{{A,E,F}, {B,C,D}}
...} # I left out a bunch, but I think you get the idea of what I need
我一直在尝试使用如下所示的itertools.combinations,然后使用递归方法生成集合的其余部分(每个组合输出中不显示的字母),但我没有收到所需的输出。
combinations = set(itertools.chain.from_iterable(itertools.combinations(iterable, r) for r in range(len(iterable)+1)))