Search All of the Math Forum:

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

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

 Messages: [ Previous | Next ]
 Daniel Huber Posts: 7 Registered: 6/16/10
Re: de-nesting complex nested lists
Posted: Jul 25, 2010 7:46 AM

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}} ) ?
>
>
> 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

Date Subject Author
7/25/10 Stern
7/25/10 Ray Koopman
7/25/10 Daniel Huber
7/25/10 David Bailey
7/25/10 nma
7/26/10 Vince Virgilio
7/26/10 szhorvat@gmail.com
7/26/10 Peter Breitfeld