       Re: Interrogating lists of unequal lenghths

• To: mathgroup at smc.vnet.net
• Subject: [mg67378] Re: [mg67367] Interrogating lists of unequal lenghths
• From: Ken Levasseur <klevasseur at mac.com>
• Date: Wed, 21 Jun 2006 02:12:33 -0400 (EDT)
• References: <200606200615.CAA15916@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```If you only want the length of each item in list x, why not  Map
[Length,x]  ?
If the list is more complex, you could define a function like this:

structure[a_List] := {Length[a], structure /@ a}
structure[a_] := 0

Then if
test = {{a}, b, {c, d}, {e, {f1, f2}, g}}

structure[test]
{4, {{1, {0}}, 0, {2, {0, 0}}, {3, {0, {2, {0, 0}}, 0}}}}

Ken Levasseur
UMass Lowell

On Jun 20, 2006, at 2:15 AM, kevin_jazz wrote:

> I'm trying to understand how to assess the dimensions of a list
> containing elements of unequal length.
> Let's say I have the list with elements of equal sizes
>
> In:=
> y={{1,2},{3,4},{5,6}}
>
> Out=
> {{1,2},{3,4},{5,6}}
>
> In:=
> Dimensions[y]
>
> Out=
> {3,2}
>
> Using the Dimensions function I can determine the size of the
> resulting
> array. If, on the other hand, I set up the following list
>
> In:=
> x={{1},{2,3},{4,5,6,7}}
>
> In:=
> Dimensions[x]
>
> Out=
> {3}
>
> The Dimensions command tells me I have only 3 elements.  But, I need
> some way to figure out that the first sublist has length 1, second has
> length 2, and the third has length 4 in some automated fashion. I've
> looked through the other commands like Depth and Length but I don't
> see
> anything that does this.
>
> What's the right to do it?
>
> Thanks,
>
> Kevin
>

```

• Prev by Date: solving with inverse functions/inexact coefficients
• Next by Date: Re: Re: Help: ratio of integral of f(x)^2 to square of integral of f(x)
• Previous by thread: Re: Interrogating lists of unequal lenghths
• Next by thread: Re: Interrogating lists of unequal lenghths