MathGroup Archive 2004

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

Search the Archive

Re: labeling problem


lst={{a,b},{c,d},e,f,{g,h,i},j,k,
      {l.m},{n,o,p},q,{r,s},{{t}}};

ToExpression[Table[
      "p"<>ToString[k]<> "="<>ToString[lst[[k]]],
      {k,Length[lst]}]];

p5

{g,h,i}

p9

{n,o,p}


Bob Hanlon

In article <c0utqu$e60$1 at smc.vnet.net>, Janos <janos.lobb at yale.edu> wrote:

<< I need to assign  names to list elements in a nested list based upon 
their position in the nested list.  For example if I have a list:

lst = {{a,b},{c,d},e,f,{g,h,i},j,k,{l.m},{n,o,p},q,{r,s},{{t}}}

then
pos=Position[lst,{_,_,_}] will give me

{{5}.{9}}

Now, I am thinking to assign a unique name to the list elements on 
these positions, like p5={g,h,i} and p9={n,o,p}.  I did not find yet 
how to create variable names with concatenation auto-magically from 
program.  In other programming languages I can do something like this:

var="p"+NumToString[5]
&var={a,b,c}

and I could refer to it afterward as p5 and its value would be {a,b,c}. 


  • Prev by Date: RE: Bloomberg and Mathematica
  • Next by Date: Re: labeling problem
  • Previous by thread: Re: labeling problem
  • Next by thread: Re: labeling problem