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)]
精彩评论