From: Michael Stern on
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

From: Norbert Marxer on
On Jul 25, 8:00 am, Michael Stern <nycst...(a)gmail.com> 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

Hello

Try
list = {{1, 2, 3}, {1, 2, 4}, {{1, 2, 3, 4}, {1, 2, 3, 8}},
{{1, 2, 9}, {{1, 2, 13}, {4, 5, 6}}}};

Cases[list, x_ /; VectorQ[x] == True, Infinity]
or
Extract[list, Position[list, x_ /; VectorQ[x] == True]]

Best Regards
Norbert Marxer

From: Ray Koopman on
On Jul 24, 11:00 pm, Michael Stern <nycst...(a)gmail.com> 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

f[a_] := If[VectorQ[a],a,Sequence@@(f/@a)]

f /@ {{1,2,3}, {1,2,4}, {{1,2,3,4}, {1,2,3,8}},
{{1,2,9}, {{1,2,13}, {4,5,6}}}}

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

From: David Park on
Two methods:

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

Cases[test, {(_?NumericQ) ..}, \[Infinity]]

Nest[Map[Sequence @@ # &, #, {-3}] &, test, Depth[test] - 3]


David Park
djmpark(a)comcast.net
http://home.comcast.net/~djmpark/



From: Michael Stern [mailto:nycstern(a)gmail.com]

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



From: Daniel Huber on
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