Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: de-nesting complex nested lists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg111289] Re: de-nesting complex nested lists
  • From: Szabolcs Horvát <szhorvat at gmail.com>
  • Date: Mon, 26 Jul 2010 06:38:42 -0400 (EDT)
  • References: <i2gjui$am$1@smc.vnet.net>

On 2010.07.25. 8: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}} ) ?
>


Hi MathGroup,

Here's a little trick to do this in a single step:

d = {{1, 2, 3}, {1, 2,  4}, {{1, 2, 3, 4}, {1, 2, 3, 8}}, {{1, 2, 9}, 
{{1, 2, 13}, {4, 5, 6}}}}

Level[d, {-2}]

Just use the leaves of the tree as reference when taking the items, not 
the root.  That is, use a negative value in the level specification.

Cheers,
Szabolcs


  • Prev by Date: NDSolve - how to bypass safety chceck?
  • Next by Date: Re: Help with an ODE
  • Previous by thread: Re: de-nesting complex nested lists
  • Next by thread: Re: de-nesting complex nested lists