Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: de-nesting complex nested lists
Replies: 7   Last Post: Jul 26, 2010 7:18 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Daniel Huber

Posts: 7
Registered: 6/16/10
Re: de-nesting complex nested lists
Posted: Jul 25, 2010 7:46 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On 25.07.2010 08:00, Michael Stern wrote:
> If one has an irregularly nested list like
>
> {{1, 2, 3}, {1, 2, 4}, {{1, 2, 3, 4}, {1, 2, 3, 8}}, {{1, 2, 9}, {{1, 2, 13}, {4, 5, 6}}}},
>
> How might one most easily transform this into a list of uniform Depth 2 ( {{1,2,3},{1,2,4},{1,2,3,4},{1,2,3,8},{1,2,9},{1,2,13},{4,5,6}} ) ?
>
> Thanks in advance,
>
> Michael
>

Hi Michael,
you could e.g. try:

t = {{1, 2, 3}, {1, 2, 4}, {{1, 2, 3, 4}, {1, 2, 3, 8}}, {{1, 2, 9},
{{1, 2, 13}, {4, 5, 6}}}};
t //. {a : {__} ..} -> a // List

cheers, Daniel




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.