string = 'abc'.所述字符串的所有子集是:[a b c ab abc ac bc '(空字符串)'].我需要使用递归函数生成所有这些子集,但我不知道如何.
string = 'abc'. All subsets of said string are: [a b c ab abc ac bc '(empty string)']. I need to generate all of these subsets using a recursive function, but I can't figure out how.
推荐答案只是为了好玩,你可以把它写成一行 lambda.
Just for kicks, you can write it as a one line lambda.
lambda s: { s[j:(j+i)] for i in range(len(s)+1) for j in range(len(s)-i+1) }