I would like to have a function split_list([1,2,4,3])
which yields the following 7 lists:
[[1], [2,4,3]]
[[1,2], [4,3]]
[[1,2,4], [3]]
[[1,2], [4],[3]]
[[1],[2,4],[3]]
[[1],[2],[4,3]]
[[1],[2],[4],[3]]
where the smaller lists are yielded first - [[1], [2,4,3]]
has length 2 while [[1],[2],[4],[3]]
is yielded last because its length is 4. This is as far as I have gotten with it:
def split_list(l):
for i in range(1, len(l)):
yield [l[:i],l[i:]]
for i in split_list((1,2,4,3)):
print(i)