- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
JSL Question: How to 'flatten" a list of lists
I would like to convert a "list of lists" e.g.
mylist={{"a","b"}, {"c", "d"}, {"e","f", "g"}}
into a simple list with each element from the nested lists e.g.
// desired outcome is this list
flat_list={"a","b","c","d","e","f","g"}
Is there a simple way to do this in JSL?
In general, the nested lists may also contain lists, and the depth of nesting may not be the same for each element in the starting list, e.g.
wild_list={{"a", {"b", "c"}}, {"d"}, {{"e", {"f"}}, "g"}};
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: JSL Question: How to 'flatten" a list of lists
Created:
May 8, 2018 01:25 AM
| Last Modified: May 8, 2018 10:57 AM
(6740 views)
| Posted in reply to message from MathStatChem 05-07-2018
Attached is a script using charcter functions. This can also be done with recursion.
4 REPLIES 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: JSL Question: How to 'flatten" a list of lists
Created:
May 8, 2018 01:25 AM
| Last Modified: May 8, 2018 10:57 AM
(6741 views)
| Posted in reply to message from MathStatChem 05-07-2018
Attached is a script using charcter functions. This can also be done with recursion.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: JSL Question: How to 'flatten" a list of lists
Much thanks, very helpful. I like the recursive function, and I will make use of it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: JSL Question: How to 'flatten" a list of lists
With you permission, I'd like to put you script in as a JSL cookbook item. Let me know if that's ok with you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: JSL Question: How to 'flatten" a list of lists
Sure, go for it.