目前已知这个方法能满足这个题目, 但是空间或运算量太大, 想请问有没有别的做法?
import itertools
powerset = lambda iterable: itertools.chain.from_iterable(
itertools.combinations(list(iterable), r)
for r in range(len(list(iterable)) + 1))
flatten = lambda list2d: [item for sublist in list2d for item in sublist]
x = list("abcd")
xx = [list(val) for val in list(powerset(x)) if 0 != len(val)]
xxx = [list(val) for val in list(powerset(xx)) if 0 != len(val)]
xxxx = [list(val) for val in xxx if x == list(sorted(flatten(val)))]
xxxx =
[[['a', 'b', 'c', 'd']],
[['a'], ['b', 'c', 'd']],
[['b'], ['a', 'c', 'd']],
[['c'], ['a', 'b', 'd']],
[['d'], ['a', 'b', 'c']],
[['a', 'b'], ['c', 'd']],
[['a', 'c'], ['b', 'd']],
[['a', 'd'], ['b', 'c']],
[['a'], ['b'], ['c', 'd']],
[['a'], ['c'], ['b', 'd']],
[['a'], ['d'], ['b', 'c']],
[['b'], ['c'], ['a', 'd']],
[['b'], ['d'], ['a', 'c']],
[['c'], ['d'], ['a', 'b']],
[['a'], ['b'], ['c'], ['d']]]