MathGroup Archive 2011

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

Search the Archive

Re: count the number of sub-list in a list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg122252] Re: count the number of sub-list in a list
  • From: dimitris <dimmechan at yahoo.com>
  • Date: Sat, 22 Oct 2011 06:08:09 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <j7rl28$i7v$1@smc.vnet.net>

On Oct 21, 2:29 pm, Gy Peng <hitphy... at gmail.com> wrote:
> Dear All,
>
> I have a list like:
>
> {{{{-0.00201671, 0.87571, 0.482832}, {-0.839678,
>     0.260735, -0.476401}, {-0.543081, -0.406384,
>     0.734789}}, {{-0.87571, -0.00201671,
>     0.482832}, {-0.260735, -0.839678, -0.476401}, {0.406384, -0.543081,
> 0.734789}}, {{0.00201671, -0.87571,
>     0.482832}, {0.839678, -0.260735, -0.476401}, {0.543081, 0.406384,
>     0.734789}}, {{0.87571, 0.00201671, 0.482832}, {0.260735,
>     0.839678, -0.476401}, {-0.406384, 0.543081,
>     0.734789}}}, {{{0.839678, -0.260735, 0.476401}, {-0.00201671,
>     0.87571, 0.482832}, {-0.543081, -0.406384, 0.734789}}, {{0.260735,
>      0.839678, 0.476401}, {-0.87571, -0.00201671,
>     0.482832}, {0.406384, -0.543081, 0.734789}}, {{-0.839678,
>     0.260735, 0.476401}, {0.00201671, -0.87571, 0.482832}, {0.543081,
>     0.406384, 0.734789}}, {{-0.260735, -0.839678, 0.476401}, {0.87571,
>      0.00201671, 0.482832}, {-0.406384, 0.543081,
>     0.734789}}}, {{{0.00201671, -0.87571, -0.482832}, {0.839678, -0.260735,
> 0.476401}, {-0.543081, -0.406384, 0.734789}}, {{0.87571,
>     0.00201671, -0.482832}, {0.260735, 0.839678,
>     0.476401}, {0.406384, -0.543081, 0.734789}}, {{-0.00201671,
>     0.87571, -0.482832}, {-0.839678, 0.260735, 0.476401}, {0.543081,
>     0.406384,
>     0.734789}}, {{-0.87571, -0.00201671, -0.482832}, {-0.260735, -0.839678,
> 0.476401}, {-0.406384, 0.543081, 0.734789}}}, {{{-0.839678,
>      0.260735, -0.476401}, {0.00201671, -0.87571, -0.482832}, {-0.543081,
> -0.406384,
>     0.734789}}, {{-0.260735, -0.839678, -0.476401}, {0.87571,
>     0.00201671, -0.482832}, {0.406384, -0.543081,
>     0.734789}}, {{0.839678, -0.260735, -0.476401}, {-0.00201671,
>     0.87571, -0.482832}, {0.543081, 0.406384, 0.734789}}, {{0.260735,
>     0.839678, -0.476401}, {-0.87571, -0.00201671, -0.482832}, {-0.406384,
> 0.543081, 0.734789}}}}
>
> I consider each of {{*, *, *}, {*, *, *}, {*,*,*}} is one single element, so
> how could I count how many element in the whole list? Thank you very much!
>
> G

I must admit that I am not exactly sure what you want.
I guess something from the following will be helpful.

In[137]:=
lst = {{{{-0.00201671, 0.87571, 0.482832}, {-0.839678,
      0.260735, -0.476401}, {-0.543081, -0.406384,
      0.734789}}, {{-0.87571, -0.00201671,
      0.482832}, {-0.260735, -0.839678, -0.476401}, {0.406384, \
-0.543081, 0.734789}}, {{0.00201671, -0.87571,
      0.482832}, {0.839678, -0.260735, -0.476401}, {0.543081,
      0.406384, 0.734789}}, {{0.87571, 0.00201671,
      0.482832}, {0.260735, 0.839678, -0.476401}, {-0.406384,
      0.543081, 0.734789}}}, {{{0.839678, -0.260735,
      0.476401}, {-0.00201671, 0.87571,
      0.482832}, {-0.543081, -0.406384, 0.734789}}, {{0.260735,
      0.839678, 0.476401}, {-0.87571, -0.00201671,
      0.482832}, {0.406384, -0.543081, 0.734789}}, {{-0.839678,
      0.260735, 0.476401}, {0.00201671, -0.87571,
      0.482832}, {0.543081, 0.406384,
      0.734789}}, {{-0.260735, -0.839678, 0.476401}, {0.87571,
      0.00201671, 0.482832}, {-0.406384, 0.543081,
      0.734789}}}, {{{0.00201671, -0.87571, -0.482832}, {0.839678, \
-0.260735, 0.476401}, {-0.543081, -0.406384, 0.734789}}, {{0.87571,
      0.00201671, -0.482832}, {0.260735, 0.839678,
      0.476401}, {0.406384, -0.543081, 0.734789}}, {{-0.00201671,
      0.87571, -0.482832}, {-0.839678, 0.260735, 0.476401}, {0.543081,
       0.406384,
      0.734789}}, {{-0.87571, -0.00201671, -0.482832}, {-0.260735, \
-0.839678, 0.476401}, {-0.406384, 0.543081, 0.734789}}}, {{{-0.839678,
       0.260735, -0.476401}, {0.00201671, -0.87571, -0.482832}, \
{-0.543081, -0.406384,
      0.734789}}, {{-0.260735, -0.839678, -0.476401}, {0.87571,
      0.00201671, -0.482832}, {0.406384, -0.543081,
      0.734789}}, {{0.839678, -0.260735, -0.476401}, {-0.00201671,
      0.87571, -0.482832}, {0.543081, 0.406384,
      0.734789}}, {{0.260735,
      0.839678, -0.476401}, {-0.87571, -0.00201671, -0.482832}, \
{-0.406384, 0.543081, 0.734789}}}};

In[152]:= Length[lst]
Length /@ lst
Map[Length, lst, {2}]

Out[152]= 4

Out[153]= {4, 4, 4, 4}

Out[154]= {{3, 3, 3, 3}, {3, 3, 3, 3}, {3, 3, 3, 3}, {3, 3, 3, 3}}

Dimitris



  • Prev by Date: Clean up code to run faster
  • Next by Date: a bug in Integrate
  • Previous by thread: Re: count the number of sub-list in a list
  • Next by thread: Full simplify problem