列表的连续子集
给定一个列表,
{"a", "b", "c", "d"}
是否有更简单的方法来生成这样的顺序子集列表(结果的顺序并不重要)
{
{"a"},
{"a b"},
{"a b c"},
{"a b c d"},
{"b"},
{"b c"},
{"b c d"},
{"c"},
{"c d"},
{"d"}
}
Given a list say
{"a", "b", "c", "d"}
Is there any easier way to generate list of sequential subsets like this (order of the result is not important)
{
{"a"},
{"a b"},
{"a b c"},
{"a b c d"},
{"b"},
{"b c"},
{"b c d"},
{"c"},
{"c d"},
{"d"}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
给出
gives
这个怎么样:
这给出了
How about this:
which gives
我更喜欢 TomD 的方法,但这就是我想到的,没有字符串处理:
I like TomD's method better, but this is what came to my mind, sans string processing:
这是一种可能的解决方案
结果
Here is one possible solution
Result
一种方式:
给予
one way:
gives
你可以这样做:
输出将如下所示:
You can do it like this:
the output will look like this:
我想我最喜欢这个:
通过字符串连接:
以类似的方式,特定于字符串:
因为纳赛尔说我在作弊,所以这里有一个更手动的方法,在大型集合上也具有更高的效率:
I think I like this best of all:
With the string joining:
In a similar vein, specific to strings:
Since Nasser says I am cheating, here is a more manual approach that also has greater efficiency on large sets: