开发者

Making a list of all sublists of a list, starting from the beginning of the original list

For example, if x is [1,2,3,4] then my program returns

     [ [], [1], [1,2], [1,2,3], 开发者_开发知识库[1,2,3,4] ]


That would be:

[x[:i] for i in range(len(x) + 1)]


x = [1, 2, 3, 4]
print [x[:i] for i in xrange(len(x) + 1)]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜