Transforming a list to list of lists using a specific ruleSplitting up delimited data in listsSelecting a list from a list of listsPartitioning time series data in sublists by their durationFinding pairs where the intersection of them is empty set from a nested listWay to generate all multisetsGrouping by total length of elements groupedHow to split list into segments based on first element of sublist, and remove ineligible segmentsGathering a List efficientlyRandomly merge elements from paired lists to a new paired listSelecting elements satisfying a condition
Managing heat dissipation in a magic wand
JavaScript: Access 'this' when calling function stored in variable
Download app bundles from App Store to run on iOS Emulator on Mac
Shell builtin `printf` line limit?
Ribbon Cable Cross Talk - Is there a fix after the fact?
Proto-Indo-European (PIE) words with IPA
Why is this python script running in background consuming 100 % CPU?
Coloring lines in a graph the same color if they are the same length
Is there an idiom that means that you are in a very strong negotiation position in a negotiation?
Variable does not Exist: CaseTrigger
A nasty indefinite integral
nginx conf: http2 module not working in Chrome in ubuntu 18.04
Why is 'additive' EQ more difficult to use than 'subtractive'?
Real Analysis: Proof of the equivalent definitions of the derivative.
Does the fact that we can only measure the two-way speed of light undermine the axiom of invariance?
Which are the advantages/disadvantages of includestandalone?
Is it normal to "extract a paper" from a master thesis?
amsmath: How can I use the equation numbering and label manually and anywhere?
Surface of the 3x3x3 cube as a graph
Existence of a model of ZFC in which the natural numbers are really the natural numbers
size of pointers and architecture
why "American-born", not "America-born"?
Does ls -R make any sense with -d?
Salesforce bug enabled "Modify All"
Transforming a list to list of lists using a specific rule
Splitting up delimited data in listsSelecting a list from a list of listsPartitioning time series data in sublists by their durationFinding pairs where the intersection of them is empty set from a nested listWay to generate all multisetsGrouping by total length of elements groupedHow to split list into segments based on first element of sublist, and remove ineligible segmentsGathering a List efficientlyRandomly merge elements from paired lists to a new paired listSelecting elements satisfying a condition
$begingroup$
Say, we have a list: l = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 and a corresponding list: v = 2,3,2,3,4. We want to split l into sublists of certain length of consecutive elements ofl and v basically tells us what that length should be. So, in this case, our output would be:
1,2,3,4,5,6,7,8,9,10,11,12,13,14
I have written a function that works:
g[l_List] := Module[split,
split =Table[, i,1,Length @ l];
split[[1]] = Table[i,i,1,First @ l];
Table[split[[i+1]] = Table[j,j,Last @ split[[i]] + 1 ,Total @ l[[1;;i+1]]],
i,1,Length@l - 1];
split
]
g@v
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
But I'm sure this could be done in a nicer, and more importantly, more efficient way. Any hints?
list-manipulation
$endgroup$
add a comment |
$begingroup$
Say, we have a list: l = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 and a corresponding list: v = 2,3,2,3,4. We want to split l into sublists of certain length of consecutive elements ofl and v basically tells us what that length should be. So, in this case, our output would be:
1,2,3,4,5,6,7,8,9,10,11,12,13,14
I have written a function that works:
g[l_List] := Module[split,
split =Table[, i,1,Length @ l];
split[[1]] = Table[i,i,1,First @ l];
Table[split[[i+1]] = Table[j,j,Last @ split[[i]] + 1 ,Total @ l[[1;;i+1]]],
i,1,Length@l - 1];
split
]
g@v
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
But I'm sure this could be done in a nicer, and more importantly, more efficient way. Any hints?
list-manipulation
$endgroup$
1
$begingroup$
It might be worth thinking about what happens whenTotal@vdoes not equalLength@l.
$endgroup$
– geordie
May 8 at 12:07
1
$begingroup$
In my case that is always the case, but yeah, it's a valid point.
$endgroup$
– amator2357
May 8 at 12:19
add a comment |
$begingroup$
Say, we have a list: l = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 and a corresponding list: v = 2,3,2,3,4. We want to split l into sublists of certain length of consecutive elements ofl and v basically tells us what that length should be. So, in this case, our output would be:
1,2,3,4,5,6,7,8,9,10,11,12,13,14
I have written a function that works:
g[l_List] := Module[split,
split =Table[, i,1,Length @ l];
split[[1]] = Table[i,i,1,First @ l];
Table[split[[i+1]] = Table[j,j,Last @ split[[i]] + 1 ,Total @ l[[1;;i+1]]],
i,1,Length@l - 1];
split
]
g@v
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
But I'm sure this could be done in a nicer, and more importantly, more efficient way. Any hints?
list-manipulation
$endgroup$
Say, we have a list: l = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 and a corresponding list: v = 2,3,2,3,4. We want to split l into sublists of certain length of consecutive elements ofl and v basically tells us what that length should be. So, in this case, our output would be:
1,2,3,4,5,6,7,8,9,10,11,12,13,14
I have written a function that works:
g[l_List] := Module[split,
split =Table[, i,1,Length @ l];
split[[1]] = Table[i,i,1,First @ l];
Table[split[[i+1]] = Table[j,j,Last @ split[[i]] + 1 ,Total @ l[[1;;i+1]]],
i,1,Length@l - 1];
split
]
g@v
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
But I'm sure this could be done in a nicer, and more importantly, more efficient way. Any hints?
list-manipulation
list-manipulation
asked May 8 at 10:30
amator2357amator2357
66810
66810
1
$begingroup$
It might be worth thinking about what happens whenTotal@vdoes not equalLength@l.
$endgroup$
– geordie
May 8 at 12:07
1
$begingroup$
In my case that is always the case, but yeah, it's a valid point.
$endgroup$
– amator2357
May 8 at 12:19
add a comment |
1
$begingroup$
It might be worth thinking about what happens whenTotal@vdoes not equalLength@l.
$endgroup$
– geordie
May 8 at 12:07
1
$begingroup$
In my case that is always the case, but yeah, it's a valid point.
$endgroup$
– amator2357
May 8 at 12:19
1
1
$begingroup$
It might be worth thinking about what happens when
Total@v does not equal Length@l.$endgroup$
– geordie
May 8 at 12:07
$begingroup$
It might be worth thinking about what happens when
Total@v does not equal Length@l.$endgroup$
– geordie
May 8 at 12:07
1
1
$begingroup$
In my case that is always the case, but yeah, it's a valid point.
$endgroup$
– amator2357
May 8 at 12:19
$begingroup$
In my case that is always the case, but yeah, it's a valid point.
$endgroup$
– amator2357
May 8 at 12:19
add a comment |
1 Answer
1
active
oldest
votes
$begingroup$
you can use this built-in
TakeList[l,v]
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
the above solution works with version 11.3
If you have an older version try
FoldPairList[TakeDrop,l,v]
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
$endgroup$
$begingroup$
Brilliant, thank you!
$endgroup$
– amator2357
May 8 at 10:34
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "387"
;
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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%2fmathematica.stackexchange.com%2fquestions%2f197933%2ftransforming-a-list-to-list-of-lists-using-a-specific-rule%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
you can use this built-in
TakeList[l,v]
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
the above solution works with version 11.3
If you have an older version try
FoldPairList[TakeDrop,l,v]
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
$endgroup$
$begingroup$
Brilliant, thank you!
$endgroup$
– amator2357
May 8 at 10:34
add a comment |
$begingroup$
you can use this built-in
TakeList[l,v]
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
the above solution works with version 11.3
If you have an older version try
FoldPairList[TakeDrop,l,v]
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
$endgroup$
$begingroup$
Brilliant, thank you!
$endgroup$
– amator2357
May 8 at 10:34
add a comment |
$begingroup$
you can use this built-in
TakeList[l,v]
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
the above solution works with version 11.3
If you have an older version try
FoldPairList[TakeDrop,l,v]
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
$endgroup$
you can use this built-in
TakeList[l,v]
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
the above solution works with version 11.3
If you have an older version try
FoldPairList[TakeDrop,l,v]
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
edited May 8 at 10:34
answered May 8 at 10:32
J42161217J42161217
5,280425
5,280425
$begingroup$
Brilliant, thank you!
$endgroup$
– amator2357
May 8 at 10:34
add a comment |
$begingroup$
Brilliant, thank you!
$endgroup$
– amator2357
May 8 at 10:34
$begingroup$
Brilliant, thank you!
$endgroup$
– amator2357
May 8 at 10:34
$begingroup$
Brilliant, thank you!
$endgroup$
– amator2357
May 8 at 10:34
add a comment |
Thanks for contributing an answer to Mathematica Stack Exchange!
- 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.
Use MathJax to format equations. MathJax reference.
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%2fmathematica.stackexchange.com%2fquestions%2f197933%2ftransforming-a-list-to-list-of-lists-using-a-specific-rule%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
1
$begingroup$
It might be worth thinking about what happens when
Total@vdoes not equalLength@l.$endgroup$
– geordie
May 8 at 12:07
1
$begingroup$
In my case that is always the case, but yeah, it's a valid point.
$endgroup$
– amator2357
May 8 at 12:19