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: [mg111415] Re: de-nesting complex nested lists
  • From: Michael Stern <nycstern at gmail.com>
  • Date: Sat, 31 Jul 2010 02:42:14 -0400 (EDT)

Thanks to everybody who responded; there were many excellent answers. This 
one is the most jaw-dropping; even reading the documentation for Level[] I 
would not have realized this would work.

Michael


On Jul 26, 2010, at 6:38 AM, Szabolcs Horv=E1t wrote:

> 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: Re: NDSolve - how to bypass safety chceck?
  • Next by Date: Re: How to remove cells with a style?
  • Previous by thread: Re: de-nesting complex nested lists
  • Next by thread: Documentation on (Color) Blend