Sub lists of list

Multi tool use
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)
python
|
show 4 more comments
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)
python
What do you mean by smaller lists?
– HakunaMaData
Dec 28 '18 at 21:37
@RobS The length of [[1], [2,4,3]] is 2 while the length of [[1],[2],[4],[3]] is 4.
– Baz
Dec 28 '18 at 21:40
maybe dupe: How to find all partitions of a list S into k subsets (can be empty)?
– wim
Dec 28 '18 at 21:41
or: How to split a list into n groups in all possible combinations of group length and elements within group?
– wim
Dec 28 '18 at 21:42
1
Do you want to exclude the main list as the first element? For example [[1, 2, 3, 4]]
– Daniel Mesejo
Dec 28 '18 at 22:02
|
show 4 more comments
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)
python
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)
python
python
edited Dec 28 '18 at 21:41
Baz
asked Dec 28 '18 at 21:33
BazBaz
1,5462778191
1,5462778191
What do you mean by smaller lists?
– HakunaMaData
Dec 28 '18 at 21:37
@RobS The length of [[1], [2,4,3]] is 2 while the length of [[1],[2],[4],[3]] is 4.
– Baz
Dec 28 '18 at 21:40
maybe dupe: How to find all partitions of a list S into k subsets (can be empty)?
– wim
Dec 28 '18 at 21:41
or: How to split a list into n groups in all possible combinations of group length and elements within group?
– wim
Dec 28 '18 at 21:42
1
Do you want to exclude the main list as the first element? For example [[1, 2, 3, 4]]
– Daniel Mesejo
Dec 28 '18 at 22:02
|
show 4 more comments
What do you mean by smaller lists?
– HakunaMaData
Dec 28 '18 at 21:37
@RobS The length of [[1], [2,4,3]] is 2 while the length of [[1],[2],[4],[3]] is 4.
– Baz
Dec 28 '18 at 21:40
maybe dupe: How to find all partitions of a list S into k subsets (can be empty)?
– wim
Dec 28 '18 at 21:41
or: How to split a list into n groups in all possible combinations of group length and elements within group?
– wim
Dec 28 '18 at 21:42
1
Do you want to exclude the main list as the first element? For example [[1, 2, 3, 4]]
– Daniel Mesejo
Dec 28 '18 at 22:02
What do you mean by smaller lists?
– HakunaMaData
Dec 28 '18 at 21:37
What do you mean by smaller lists?
– HakunaMaData
Dec 28 '18 at 21:37
@RobS The length of [[1], [2,4,3]] is 2 while the length of [[1],[2],[4],[3]] is 4.
– Baz
Dec 28 '18 at 21:40
@RobS The length of [[1], [2,4,3]] is 2 while the length of [[1],[2],[4],[3]] is 4.
– Baz
Dec 28 '18 at 21:40
maybe dupe: How to find all partitions of a list S into k subsets (can be empty)?
– wim
Dec 28 '18 at 21:41
maybe dupe: How to find all partitions of a list S into k subsets (can be empty)?
– wim
Dec 28 '18 at 21:41
or: How to split a list into n groups in all possible combinations of group length and elements within group?
– wim
Dec 28 '18 at 21:42
or: How to split a list into n groups in all possible combinations of group length and elements within group?
– wim
Dec 28 '18 at 21:42
1
1
Do you want to exclude the main list as the first element? For example [[1, 2, 3, 4]]
– Daniel Mesejo
Dec 28 '18 at 22:02
Do you want to exclude the main list as the first element? For example [[1, 2, 3, 4]]
– Daniel Mesejo
Dec 28 '18 at 22:02
|
show 4 more comments
3 Answers
3
active
oldest
votes
If including the list itself as the first element is not a problem, you could so something like this:
def split_list(lst):
if not lst:
yield
for i in range(len(lst), 0, -1):
for j in split_list(lst[i:]):
yield [lst[:i]] + j
for l in split_list([1, 2, 4, 3]):
print(l)
Output
[[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]]
[[1], [2], [4], [3]]
add a comment |
You can utilize list slicing with recursion:
def split_list(d):
for i in range(len(d)):
if len(d[i+1:]) > 0:
for c in split_list(d[i+1:]):
yield [d[:i+1], *c]
else:
yield [d]
print(list(split_list([1,2,4,3])))
Output:
[[[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]], [[1, 2, 4, 3]]]
Edit: event shorter
def split_list(d):
if len(d) > 1:
return [list(filter(None, [d[:i+1], *c])) for i in range(len(d)) for c in split_list(d[i+1:])]
return [d] if not isinstance(d, list) else [[d]]
Output:
[[[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]], [[1, 2, 4, 3]]]
Nice!! What does the * in *c do? unpack the list?
– HakunaMaData
Dec 28 '18 at 22:07
@RobS Yes, that is correct.*c
is simple unpacking. I think it is a bit cleaner (although that is somewhat subjective) that concatenating lists with+
.
– Ajax1234
Dec 28 '18 at 22:15
add a comment |
Try this one:
def split_list(l):
if len(l) == 1:
yield [ l ]
return
for s in split_list(l[1:]):
for n, sub in enumerate(s):
if len((s[:n] + [[ l[0] ] + sub] + s[n+1:])[0]) !=4:
yield s[:n] + [[ l[0] ] + sub] + s[n+1:]
yield [[l[0]]] + s
for lst in split_list([1, 2, 3, 4]):
print lst
The problem is solved recursively.
And in output:
[[1], [2, 3, 4]]
[[1, 2], [3, 4]]
[[2], [1, 3, 4]]
[[1], [2], [3, 4]]
[[1, 2, 3], [4]]
[[2, 3], [1, 4]]
[[1], [2, 3], [4]]
[[1, 3], [2, 4]]
[[3], [1, 2, 4]]
[[1], [3], [2, 4]]
[[1, 2], [3], [4]]
[[2], [1, 3], [4]]
[[2], [3], [1, 4]]
[[1], [2], [3], [4]]
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53964502%2fsub-lists-of-list%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
If including the list itself as the first element is not a problem, you could so something like this:
def split_list(lst):
if not lst:
yield
for i in range(len(lst), 0, -1):
for j in split_list(lst[i:]):
yield [lst[:i]] + j
for l in split_list([1, 2, 4, 3]):
print(l)
Output
[[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]]
[[1], [2], [4], [3]]
add a comment |
If including the list itself as the first element is not a problem, you could so something like this:
def split_list(lst):
if not lst:
yield
for i in range(len(lst), 0, -1):
for j in split_list(lst[i:]):
yield [lst[:i]] + j
for l in split_list([1, 2, 4, 3]):
print(l)
Output
[[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]]
[[1], [2], [4], [3]]
add a comment |
If including the list itself as the first element is not a problem, you could so something like this:
def split_list(lst):
if not lst:
yield
for i in range(len(lst), 0, -1):
for j in split_list(lst[i:]):
yield [lst[:i]] + j
for l in split_list([1, 2, 4, 3]):
print(l)
Output
[[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]]
[[1], [2], [4], [3]]
If including the list itself as the first element is not a problem, you could so something like this:
def split_list(lst):
if not lst:
yield
for i in range(len(lst), 0, -1):
for j in split_list(lst[i:]):
yield [lst[:i]] + j
for l in split_list([1, 2, 4, 3]):
print(l)
Output
[[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]]
[[1], [2], [4], [3]]
answered Dec 28 '18 at 22:04


Daniel MesejoDaniel Mesejo
15.8k21030
15.8k21030
add a comment |
add a comment |
You can utilize list slicing with recursion:
def split_list(d):
for i in range(len(d)):
if len(d[i+1:]) > 0:
for c in split_list(d[i+1:]):
yield [d[:i+1], *c]
else:
yield [d]
print(list(split_list([1,2,4,3])))
Output:
[[[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]], [[1, 2, 4, 3]]]
Edit: event shorter
def split_list(d):
if len(d) > 1:
return [list(filter(None, [d[:i+1], *c])) for i in range(len(d)) for c in split_list(d[i+1:])]
return [d] if not isinstance(d, list) else [[d]]
Output:
[[[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]], [[1, 2, 4, 3]]]
Nice!! What does the * in *c do? unpack the list?
– HakunaMaData
Dec 28 '18 at 22:07
@RobS Yes, that is correct.*c
is simple unpacking. I think it is a bit cleaner (although that is somewhat subjective) that concatenating lists with+
.
– Ajax1234
Dec 28 '18 at 22:15
add a comment |
You can utilize list slicing with recursion:
def split_list(d):
for i in range(len(d)):
if len(d[i+1:]) > 0:
for c in split_list(d[i+1:]):
yield [d[:i+1], *c]
else:
yield [d]
print(list(split_list([1,2,4,3])))
Output:
[[[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]], [[1, 2, 4, 3]]]
Edit: event shorter
def split_list(d):
if len(d) > 1:
return [list(filter(None, [d[:i+1], *c])) for i in range(len(d)) for c in split_list(d[i+1:])]
return [d] if not isinstance(d, list) else [[d]]
Output:
[[[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]], [[1, 2, 4, 3]]]
Nice!! What does the * in *c do? unpack the list?
– HakunaMaData
Dec 28 '18 at 22:07
@RobS Yes, that is correct.*c
is simple unpacking. I think it is a bit cleaner (although that is somewhat subjective) that concatenating lists with+
.
– Ajax1234
Dec 28 '18 at 22:15
add a comment |
You can utilize list slicing with recursion:
def split_list(d):
for i in range(len(d)):
if len(d[i+1:]) > 0:
for c in split_list(d[i+1:]):
yield [d[:i+1], *c]
else:
yield [d]
print(list(split_list([1,2,4,3])))
Output:
[[[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]], [[1, 2, 4, 3]]]
Edit: event shorter
def split_list(d):
if len(d) > 1:
return [list(filter(None, [d[:i+1], *c])) for i in range(len(d)) for c in split_list(d[i+1:])]
return [d] if not isinstance(d, list) else [[d]]
Output:
[[[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]], [[1, 2, 4, 3]]]
You can utilize list slicing with recursion:
def split_list(d):
for i in range(len(d)):
if len(d[i+1:]) > 0:
for c in split_list(d[i+1:]):
yield [d[:i+1], *c]
else:
yield [d]
print(list(split_list([1,2,4,3])))
Output:
[[[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]], [[1, 2, 4, 3]]]
Edit: event shorter
def split_list(d):
if len(d) > 1:
return [list(filter(None, [d[:i+1], *c])) for i in range(len(d)) for c in split_list(d[i+1:])]
return [d] if not isinstance(d, list) else [[d]]
Output:
[[[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]], [[1, 2, 4, 3]]]
edited Dec 28 '18 at 22:09
answered Dec 28 '18 at 22:02


Ajax1234Ajax1234
40.8k42653
40.8k42653
Nice!! What does the * in *c do? unpack the list?
– HakunaMaData
Dec 28 '18 at 22:07
@RobS Yes, that is correct.*c
is simple unpacking. I think it is a bit cleaner (although that is somewhat subjective) that concatenating lists with+
.
– Ajax1234
Dec 28 '18 at 22:15
add a comment |
Nice!! What does the * in *c do? unpack the list?
– HakunaMaData
Dec 28 '18 at 22:07
@RobS Yes, that is correct.*c
is simple unpacking. I think it is a bit cleaner (although that is somewhat subjective) that concatenating lists with+
.
– Ajax1234
Dec 28 '18 at 22:15
Nice!! What does the * in *c do? unpack the list?
– HakunaMaData
Dec 28 '18 at 22:07
Nice!! What does the * in *c do? unpack the list?
– HakunaMaData
Dec 28 '18 at 22:07
@RobS Yes, that is correct.
*c
is simple unpacking. I think it is a bit cleaner (although that is somewhat subjective) that concatenating lists with +
.– Ajax1234
Dec 28 '18 at 22:15
@RobS Yes, that is correct.
*c
is simple unpacking. I think it is a bit cleaner (although that is somewhat subjective) that concatenating lists with +
.– Ajax1234
Dec 28 '18 at 22:15
add a comment |
Try this one:
def split_list(l):
if len(l) == 1:
yield [ l ]
return
for s in split_list(l[1:]):
for n, sub in enumerate(s):
if len((s[:n] + [[ l[0] ] + sub] + s[n+1:])[0]) !=4:
yield s[:n] + [[ l[0] ] + sub] + s[n+1:]
yield [[l[0]]] + s
for lst in split_list([1, 2, 3, 4]):
print lst
The problem is solved recursively.
And in output:
[[1], [2, 3, 4]]
[[1, 2], [3, 4]]
[[2], [1, 3, 4]]
[[1], [2], [3, 4]]
[[1, 2, 3], [4]]
[[2, 3], [1, 4]]
[[1], [2, 3], [4]]
[[1, 3], [2, 4]]
[[3], [1, 2, 4]]
[[1], [3], [2, 4]]
[[1, 2], [3], [4]]
[[2], [1, 3], [4]]
[[2], [3], [1, 4]]
[[1], [2], [3], [4]]
add a comment |
Try this one:
def split_list(l):
if len(l) == 1:
yield [ l ]
return
for s in split_list(l[1:]):
for n, sub in enumerate(s):
if len((s[:n] + [[ l[0] ] + sub] + s[n+1:])[0]) !=4:
yield s[:n] + [[ l[0] ] + sub] + s[n+1:]
yield [[l[0]]] + s
for lst in split_list([1, 2, 3, 4]):
print lst
The problem is solved recursively.
And in output:
[[1], [2, 3, 4]]
[[1, 2], [3, 4]]
[[2], [1, 3, 4]]
[[1], [2], [3, 4]]
[[1, 2, 3], [4]]
[[2, 3], [1, 4]]
[[1], [2, 3], [4]]
[[1, 3], [2, 4]]
[[3], [1, 2, 4]]
[[1], [3], [2, 4]]
[[1, 2], [3], [4]]
[[2], [1, 3], [4]]
[[2], [3], [1, 4]]
[[1], [2], [3], [4]]
add a comment |
Try this one:
def split_list(l):
if len(l) == 1:
yield [ l ]
return
for s in split_list(l[1:]):
for n, sub in enumerate(s):
if len((s[:n] + [[ l[0] ] + sub] + s[n+1:])[0]) !=4:
yield s[:n] + [[ l[0] ] + sub] + s[n+1:]
yield [[l[0]]] + s
for lst in split_list([1, 2, 3, 4]):
print lst
The problem is solved recursively.
And in output:
[[1], [2, 3, 4]]
[[1, 2], [3, 4]]
[[2], [1, 3, 4]]
[[1], [2], [3, 4]]
[[1, 2, 3], [4]]
[[2, 3], [1, 4]]
[[1], [2, 3], [4]]
[[1, 3], [2, 4]]
[[3], [1, 2, 4]]
[[1], [3], [2, 4]]
[[1, 2], [3], [4]]
[[2], [1, 3], [4]]
[[2], [3], [1, 4]]
[[1], [2], [3], [4]]
Try this one:
def split_list(l):
if len(l) == 1:
yield [ l ]
return
for s in split_list(l[1:]):
for n, sub in enumerate(s):
if len((s[:n] + [[ l[0] ] + sub] + s[n+1:])[0]) !=4:
yield s[:n] + [[ l[0] ] + sub] + s[n+1:]
yield [[l[0]]] + s
for lst in split_list([1, 2, 3, 4]):
print lst
The problem is solved recursively.
And in output:
[[1], [2, 3, 4]]
[[1, 2], [3, 4]]
[[2], [1, 3, 4]]
[[1], [2], [3, 4]]
[[1, 2, 3], [4]]
[[2, 3], [1, 4]]
[[1], [2, 3], [4]]
[[1, 3], [2, 4]]
[[3], [1, 2, 4]]
[[1], [3], [2, 4]]
[[1, 2], [3], [4]]
[[2], [1, 3], [4]]
[[2], [3], [1, 4]]
[[1], [2], [3], [4]]
answered Dec 28 '18 at 22:55


SseinSsein
1,0141921
1,0141921
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53964502%2fsub-lists-of-list%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
EEo7oiKSJ,zJ4,ucBo4AXnwjbeg7lwsEdDbJha3QLAv3ovEqdVkhOQ9kGA7OATF3xYs1glDwHzTblbf6gb7TcbuIsJT78
What do you mean by smaller lists?
– HakunaMaData
Dec 28 '18 at 21:37
@RobS The length of [[1], [2,4,3]] is 2 while the length of [[1],[2],[4],[3]] is 4.
– Baz
Dec 28 '18 at 21:40
maybe dupe: How to find all partitions of a list S into k subsets (can be empty)?
– wim
Dec 28 '18 at 21:41
or: How to split a list into n groups in all possible combinations of group length and elements within group?
– wim
Dec 28 '18 at 21:42
1
Do you want to exclude the main list as the first element? For example [[1, 2, 3, 4]]
– Daniel Mesejo
Dec 28 '18 at 22:02